note 52478 added to function.explode

From: Date: Tue, 03 May 2005 08:07:27 +0000
Subject: note 52478 added to function.explode
Groups: php.notes 
Request: Send a blank email to php-notes+get-88895@lists.php.net to get a copy of this message
The associative array parsing example by hhabermann at pc-kiel dot de seems flawed to me. Given <?php $data = 'One:1:two:2:three:3'; ?> it should be parsed with <?php function &parse(&$data) { $data = explode("\n", $data); $num = count($data); if ($num % 2 || ! $num) { return false; } for ($i = 0; $i < $num / 2; $i++) { $ret[$data[$i * 2]] = $data[$i * 2 + 1]; } return $ret; } $data =& parse($data); print_r($data); ?> The output is as expected: Array ( [One] => 1 [two] => 2 [three] => 3 ) ---- Manual Page -- http://www.php.net/manual/en/function.explode.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+52478 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52478&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52478&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52478&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52478&report=yes&reason=useless Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52478&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+52478&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#88895) next »