我在获取此输出时遇到问题。我有一个像这样声明的数组:
$category = array(1,2,4,5,10); //category_ids
现在,我想将它传递给另一个参数:
$parameter = array(
array('category_id' => 1),
array('category_id' => 2),
array('category_id' => 4),
.
.
.
);
怎么做?
答案 0 :(得分:1)
喜欢这个:
<?php
$category = array(1,2,4,5,10); //category_ids
foreach($category as $c){
$parameter[] = array('category_id' => $c);
}
print_r($parameter);
// Output:
//Array ( [0] => Array ( [category_id] => 1 )
//[1] => Array ( [category_id] => 2 )
//[2] => Array ( [category_id] => 4 )
//[3] => Array ( [category_id] => 5 )
//[4] => Array ( [category_id] => 10 ) )