我有一个数组
array
(
[0] => bruce
)
array
(
[1] => arju
)
我想将上面的数组拆分成多个数组 例如:显示在下面
SELECT
t.id
, t.expired
, t.succ
, t.cradit_end_date
, t.user_id
, u.family
, t.coupon_code
, u.username
, d.title
, s.title as sub_title
, t.coupon_parent
, t.coupon_id
, t.coupon_property_id
FROM tractions t
LEFT OUTER JOIN traction_details d ON t.id = d.tr_id
LEFT OUTER JOIN traction_details_sub s ON t.id = s.tr_id
JOIN users u ON t.user_id = u.id
WHERE t.app='mobile' AND t.succ = 1 AND t.user_id=$user_id
答案 0 :(得分:1)
这应该有效,
<?php
$newarr1 = $_SESSION['arrt1'];
echo '<pre>';
print_r($newarr1);
echo '<pre>';
$newarray2 = array();
$i = 0;
while ($i < sizeof($newarr1))
{
$newarray2[] = array(
"person_id" => $i + 1,
"person_name" => $newarr1[$i]
);
$i++;
}
?>
编辑:
<?php
$newarr1 = $_SESSION['arrt1'];
echo '<pre>';
print_r($newarr1);
echo '<pre>';
$newarray2 = array();
$i = 0;
while ($i < sizeof($newarr1))
{
$newarray2[] = array(
$i => $newarr1[$i]
);
$i++;
}
?>
答案 1 :(得分:1)
介意我问你为什么要这样的东西?
<?php
$names = Array(
'bruce',
'arju',
'newu',
'jack',
'john',
'kyle',
'sam',
'tim'
);
for($i = 0; $i < count($names); $i++){
$name[] = array($i => $names[$i]);
}
foreach($name as $key => $val){
echo $key, ':<pre>';
print_r($val);
echo '</pre>'
}
// or you could use array_chunk
// http://php.net/manual/en/function.array-chunk.php
print_r(array_chunk($names, 1));
?>
答案 2 :(得分:1)
PHP array_chunk可能有所帮助 要打破单个数组中的数组,可以使用
$a = array_chunk($input_array, 1);
echo '<pre>';
print_r($a);
echo '</pre>';
这会给你的结果.....