这是一个非常简单的问题,我正在努力解决。我有一个变量 ($foo),它是一个从 sql 调用创建的数组。
当我在代码中引用一个字段时,有什么区别
$foo['bar']
和$foo->bar
?
$foo['bar']
references an element with the key 'bar' in an array assigned to the variable $foo, as retrieved by mysql_fetch_array()
$foo->bar
references the property called 'bar' in an object instance in the variable $foo, as retrieved by mysql_fetch_object()
The difference is the mysqli_fetch_* method you use.
'Assoc' stands for 'associated (array)'.
$foo['bar'] is used to access array index this case $foo is an array variable and $foo->bar is used to access class method . in this case $foo is a class object
$foo = new StdClass();
$foo->bar = "Anything";
or
$foo['bar'] = "dfgdfG";