note 77958 added to function.print-r

From: Date: Fri, 21 Sep 2007 12:17:33 +0000
Subject: note 77958 added to function.print-r
Groups: php.notes 
Request: Send a blank email to php-notes+get-130657@lists.php.net to get a copy of this message
If you need to import an print_R output back to an array you could use this. This could also be (ab)used to convert a object into a array... <?php function object2array($printr) { $newarray = array(); $a[0] = &$newarray; if (preg_match_all('/^\s+\[(\w+).*\] => (.*)\n/m', $printr, $match)) { foreach ($match[0] as $key => $value) { (int)$tabs = substr_count(substr($value, 0, strpos($value, "[")), " "); if ($match[2][$key] == 'Array' || substr($match[2][$key], -6) == 'Object') { $a[$tabs+1] = &$a[$tabs][$match[1][$key]]; } else { $a[$tabs][$match[1][$key]] = $match[2][$key]; } } } return $newarray; } ?> ---- Server IP: 83.137.20.107 Probable Submitter: 81.4.97.215 (proxied: 62.41.178.65) ---- Manual Page -- http://www.php.net/manual/en/function.print-r.php Edit -- https://master.php.net/note/edit/77958 Del: integrated -- https://master.php.net/note/delete/77958/integrated Del: useless -- https://master.php.net/note/delete/77958/useless Del: bad code -- https://master.php.net/note/delete/77958/bad+code Del: spam -- https://master.php.net/note/delete/77958/spam Del: non-english -- https://master.php.net/note/delete/77958/non-english Del: in docs -- https://master.php.net/note/delete/77958/in+docs Del: other reasons-- https://master.php.net/note/delete/77958 Reject -- https://master.php.net/note/reject/77958 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#130657) next »