note 122047 deleted from function.array-sum by salathe

From: Date: Mon, 21 Sep 2020 14:51:13 +0000
Subject: note 122047 deleted from function.array-sum by salathe
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-215353@lists.php.net to get a copy of this message
Note Submitter: j_mullings at hotmail dot co dot uk ---- Nice and clean if you know what I mean: function makeRecursive($ar = "") { $toflat = array( $ar ); $res = array(); while (($r = array_shift($toflat)) !== NULL) foreach ($r as $v) if (is_array($v)) $toflat[] = $v; else $res[] = $v; return $res; } $data = [0,0,0,[0,0,[0,1,0,],0],0]; echo array_sum(makeRecursive($data));

« previous php.notes (#215353) next »