note 129442 added to language.types.array

From: Date: Sun, 28 Apr 2024 06:49:31 +0000
Subject: note 129442 added to language.types.array
Groups: php.notes 
Request: Send a blank email to php-notes+get-221308@lists.php.net to get a copy of this message
Accessing elements in multi-dimensional arrays: I searched for quite a while to find this info - maybe it is not normal for PHP? anyway.... I am following a course and had an array defined thus: $recipient = [ ['name' => 'Alice', 'segment' => 'Tech Enthusiast', 'email' => 'alice@example.com'], ['name' => 'Colin', 'segment' => 'Aviator', 'email' => 'colin@duck.com'], ['name' => 'David', 'segment' => 'Health Guru', 'email' => 'david@google.com'], ]; I needed to access different elements in a foreach loop. This code will do it: foreach ($recipient as $recip){ echo $recip['name'] . ", " . $recip['segment'] . ", " . $recip['email'] . "\n"; }; Hope this helps someone. ---- Server IP: 45.112.84.4 Probable Submitter: 80.90.13.131 (proxied: 107.186.85.1) ---- Manual Page -- https://php.net/manual/en/language.types.array.php Edit -- https://main.php.net/note/edit/129442 Del: integrated -- https://main.php.net/note/delete/129442/integrated Del: useless -- https://main.php.net/note/delete/129442/useless Del: bad code -- https://main.php.net/note/delete/129442/bad+code Del: spam -- https://main.php.net/note/delete/129442/spam Del: non-english -- https://main.php.net/note/delete/129442/non-english Del: in docs -- https://main.php.net/note/delete/129442/in+docs Del: other reasons-- https://main.php.net/note/delete/129442 Reject -- https://main.php.net/note/reject/129442 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#221308) next »