note 103881 deleted from function.list by googleguy

From: Date: Thu, 13 Sep 2012 10:00:13 +0000
Subject: note 103881 deleted from function.list by googleguy
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-190692@lists.php.net to get a copy of this message
Note Submitter: Ultimater at gmail dot com ---- Note that list(...) isn't limited to scalar variables. It can even create an associative array: <?php $html=<<<EOT <table> <tr class="row-odd"> <td><span class="username">Foo</span></td> <td><span class="userid">30185</span></td> </tr><tr class="row-even"> <td><span class="username">Bar</span></td> <td><span class="userid">3093</span></td> </tr> </table> EOT; interface RegExps { const PROFILE_CONTENT='/<tr[^>]*>.*?<span class="username">(.*?)<\/span>[ ]?.*?<span class="userid">(.*?)<\/span>.*?<\/tr>/msi'; } preg_match_all(RegExps::PROFILE_CONTENT,$html, $matches,PREG_SET_ORDER); $profiles=array(); foreach($matches as $match) { $profile=array(); list(,$profile['username'],$profile['userid'])=$match; //$profile=array_reverse($profile); $profiles[]=$profile; } echo '<pre>'.print_r($profiles,true).'</pre>'; ?> Just be careful, as the manual warns us, regarding the right-most parameter being handled first. If this becomes a problem, I'd suggest using array_reverse as shown in my code.

« previous php.notes (#190692) next »