多数组排序合并
header('Content-Type:text/html; charset=utf-8');
1、第一个数组
$array1 = array(
'photo_0' => 'http://192.168.1.111/li/Public/uploads/musicalbum/2017-01-10/0.1484018695.jpg',
'photo_1' => 'http://192.168.1.111/li/Public/uploads/musicalbum/2017-01-10/1.1484018695.jpg',
'photo_2' => 'http://192.168.1.111/li/Public/uploads/musicalbum/2017-01-10/0.1484015728.jpg'
);
2、第二个数组
$array2 = array(
'content_0' => '',
'content_1' => '好朋友',
'content_2' => ''
);
3、第三个数组
$abc = array(
'photo_0' => 'http://192.168.1.111/li/Public/uploads/musicalbum/2017-01-10/0.1484018695.jpg',
'content_0' => '',
'photo_1' => 'http://192.168.1.111/li/Public/uploads/musicalbum/2017-01-10/1.1484018695.jpg',
'content_1' => '好朋友',
'photo_2' => 'http://192.168.1.111/li/Public/uploads/musicalbum/2017-01-10/0.1484015728.jpg',
'content_2' => ''
);
4、数组array1 与数组array2 合并 并排序成数组abc的排列形式
方法1
function array_merge_sort($array)
{
$data = array();
$prefixArray = array_keys($array);
$itemTotal = count(current($array));
for ($i = 0; $i < $itemTotal; $i++) {
foreach ($prefixArray as $prefix) {
if (isset($array[$prefix][$prefix . $i])) {
$data[$prefix . $i] = $array[$prefix][$prefix . $i];
}
}
}
return $data;
}
echo '<pre>';
var_dump(array_merge_sort(
array('photo_' => $array1, 'content_' => $array2)
));
方法2
$array =array();
$lenght = count($array1);
for($i=0;$i<$lenght;$i++){
$array['photo_'.$i] = $array1['photo_'.$i];
$array['content_'.$i] = $array2['content_'.$i];
}
echo '<pre>';
var_dump($array);