2010-08-29 77 views
0

我在PHP中一遍又一遍地面对这些代码,这是如何工作在PHP?这种类型的数组如何在PHP中运行?

$data[$row['id']] 

$options['data']=$row[0]; 
+2

我不明白,这些数组的哪个方面是你的问题?使用字符串和数字作为数组键还是嵌套? – 2010-08-29 21:12:14

回答

0
// Let's initialize some variables. 
$row = array(); 
$row[0] = 999; 
$row['id'] = 6; 
// $row is now equal to array(0 => 999, 'id' => 6) 

$data = array(2, 3, 5, 7, 11, 13, 17, 19); 
// $data[0] is 2; $data[1] is 3. 

// At this point, 
$data[$row['id']] == // really means... 
$data[6] ==   // which equals... 
17; 

$options['data'] = $row[0]; 
$options[] = 66; 
$options[44] = 77; 
$options[] = 88; 

// $options is now equal to array('data' => 999, 0 => 66, 44 => 77, 55 => 88) 

数组只是键 - 值对。使用$array[] =语法告诉PHP为新元素分配一个键。 PHP采用最高的整数密钥并添加一个来获取新密钥。

0

数组在PHP更像哈希,在那里他们可以有基于字符串的索引。我假设$row['id']包含一个数字或字符串,然后用于使用该键访问值。

相关问题