Home > Backend Development > PHP Tutorial > 新人,问上数组的有关问题,多谢

新人,问上数组的有关问题,多谢

WBOY
Release: 2016-06-13 13:20:57
Original
979 people have browsed it

新人,问下数组的问题,谢谢!
$f=array('0'=>array('id'=>'555','cd'=>'6666'),'1'=>array('id'=>'bbb','cd'=>'ddd'),'2'=>array('id'=>'ccc','cd'=>'ccc'));
$t = array();
foreach($f as $v){
$t[$v['id']]=$v; //这句理解不了,求开导!! 是怎么把键名变成id的值的?原理是什么?
}
print_r($t);

------解决方案--------------------
你先要知道$v是什么,就是array('id'=>'555','cd'=>'6666')这几个,$va['id']一次循环就是 555,bbb,ccc,然后$t['555'] = array...,
------解决方案--------------------
foreach($f as $v){ 后
$v 依次为
array('id'=>'555','cd'=>'6666')
array('id'=>'bbb','cd'=>'ddd')
array('id'=>'ccc','cd'=>'ccc')

$t[$v['id']] 就是
$i = $v['id'];
$t[$i]
这样就不难理解了吧

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template