如何使数组中的字段值与数组索引相同(how can i make a field value in an array the same as the array index)
我有一个显然有索引的数组..我想要将每个数组索引一个赋值作为我的数组中的值..这就是我的数组看起来像
Array ( [0] => Array ( [id] => 20 [CLASS] => 1234 [REGISTER] => 13 ) [1] => Array ( [id] => 11 [CLASS] => SEC [REGISTER] => 3 ) )我想要的是使用索引并将它们放在REGISTER字段中
Array ( [0] => Array ( [id] => 20 [CLASS] => 1234 [REGISTER] => 0 ) [1] => Array ( [id] => 11 [CLASS] => SEC [REGISTER] => 1 ) )i have an array that obviously have indexes.. i want want to take each array index an assign as a value in my array.. this is how my array looks like
Array ( [0] => Array ( [id] => 20 [CLASS] => 1234 [REGISTER] => 13 ) [1] => Array ( [id] => 11 [CLASS] => SEC [REGISTER] => 3 ) )want i want is to use the indexes and put them in the REGISTER field like this
Array ( [0] => Array ( [id] => 20 [CLASS] => 1234 [REGISTER] => 0 ) [1] => Array ( [id] => 11 [CLASS] => SEC [REGISTER] => 1 ) )最满意答案
只需迭代这个数组,如下所示:
foreach($a as $k=>$v){ $a[$k]['REGISTER'] = $k; }Just iterate over this array like this:
foreach($a as $k=>$v){ $a[$k]['REGISTER'] = $k; }更多推荐
发布评论