php - Iterate values of Associative array if it has one object or more -


my problem is, have set of arrays

$people =[{name:'alan', haschild:true},     {name:'alice', hasdetail:true}]; 

and other 1 is

$people =[{name:'alan', haschild:true}]; 

i need print elements.

i have tried in below way

for($i=0; $i<count($people); $i++){     echo $people[$i]['name']; } 

the first 1 working fine. second 1 show error this

notice: undefined offset: 0 in /opt/lampp/htdocs/vp/pending_users.php on line 320 

why happen? how overcome issue

this basic stuff. should read few beginner's tutorials.

you can loop array using foreach loop, this:

$people = [     [         'name' => 'alan',          'haschild' => true     ],     [         'name' => 'alice',          'haschild' => true     ] ];  foreach ($people $person) {     echo $person['name'] . "\n"; } 

Comments

Popular posts from this blog

android - Gradle sync Error:Configuration with name 'default' not found -

java - Andrioid studio start fail: Fatal error initializing 'null' -

html - jQuery UI Sortable - Remove placeholder after item is dropped -