note 102520 added to function.preg-match-all

From: Date: Fri, 18 Feb 2011 19:21:42 +0000
Subject: note 102520 added to function.preg-match-all
Groups: php.notes 
Request: Send a blank email to php-notes+get-177126@lists.php.net to get a copy of this message
I needed a function to rotate the results of a preg_match_all query, and made this. Not sure if it exists. function turn_array($m) { for ($z = 0;$z < count($m);$z++) { for ($x = 0;$x < count($m[$z]);$x++) { $rt[$x][$z] = $m[$z][$x]; } } return $rt; } Example - Take results of some preg_match_all query: Array ( [0] => Array ( [1] => Banff [2] => Canmore [3] => Invermere ) [1] => Array ( [1] => AB [2] => AB [3] => BC ) [2] => Array ( [1] => 51.1746254 [2] => 51.0938416 [3] => 50.5065193 ) [3] => Array ( [1] => -115.5719757 [2] => -115.3517761 [3] => -116.0321884 ) [4] => Array ( [1] => T1L 1B3 [2] => T1W 1N2 [3] => V0B 2G0 ) ) Rotate it 90 degrees to group results as records: Array ( [0] => Array ( [1] => Banff [2] => AB [3] => 51.1746254 [4] => -115.5719757 [5] => T1L 1B3 ) [1] => Array ( [1] => Canmore [2] => AB [3] => 51.0938416 [4] => -115.3517761 [5] => T1W 1N2 ) [2] => Array ( [1] => Invermere [2] => BC [3] => 50.5065193 [4] => -116.0321884 [5] => V0B 2G0 ) ) ---- Server IP: 69.147.83.197 Probable Submitter: 70.181.209.72 ---- Manual Page -- http://www.php.net/manual/en/function.preg-match-all.php Edit -- https://master.php.net/note/edit/102520 Del: integrated -- https://master.php.net/note/delete/102520/integrated Del: useless -- https://master.php.net/note/delete/102520/useless Del: bad code -- https://master.php.net/note/delete/102520/bad+code Del: spam -- https://master.php.net/note/delete/102520/spam Del: non-english -- https://master.php.net/note/delete/102520/non-english Del: in docs -- https://master.php.net/note/delete/102520/in+docs Del: other reasons-- https://master.php.net/note/delete/102520 Reject -- https://master.php.net/note/reject/102520 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#177126) next »