note 111693 added to function.array-combine

From: Date: Sun, 17 Mar 2013 20:38:29 +0000
Subject: note 111693 added to function.array-combine
Groups: php.notes 
Request: Send a blank email to php-notes+get-194103@lists.php.net to get a copy of this message
a little (and blazing-fast) code to convert tags to array (xml, html, etc): <?php function array_combine_($keys, $values) { $result = array(); foreach ($keys as $i => $k) { $result[$k][] = $values[$i]; } array_walk($result, create_function('&$v', '$v = (count($v) == 1)? array_pop($v): $v;')); return $result; } function extract_data($str) { return (is_array($str))? array_map(__NAMESPACE__. '\extract_data', $str): ((!preg_match_all('#<([A-Za-z0-9]*)(?:\s+[^>]+)?>(.*?)</\1>#s', $str, $matches))? $str: array_map((__NAMESPACE__. '\extract_data'), array_combine_($matches[1], $matches[2]))); } print_r(extract_data("<a><b>1</b><c>2</c><c>3</c></a>")); ?> Results: [a] => Array ( [b] => 1 [c] => Array ( [0] => 2 [1] => 3 ) ) ---- Server IP: 69.147.83.199 Probable Submitter: 189.27.147.21 ---- Manual Page -- http://php.net/manual/en/function.array-combine.php Edit -- https://master.php.net/note/edit/111693 Del: integrated -- https://master.php.net/note/delete/111693/integrated Del: useless -- https://master.php.net/note/delete/111693/useless Del: bad code -- https://master.php.net/note/delete/111693/bad+code Del: spam -- https://master.php.net/note/delete/111693/spam Del: non-english -- https://master.php.net/note/delete/111693/non-english Del: in docs -- https://master.php.net/note/delete/111693/in+docs Del: other reasons-- https://master.php.net/note/delete/111693 Reject -- https://master.php.net/note/reject/111693 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#194103) next »