note 52075 deleted from ref.array by tularis

From: Date: Sun, 26 Aug 2007 16:40:01 +0000
Subject: note 52075 deleted from ref.array by tularis
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-129815@lists.php.net to get a copy of this message
Note Submitter: admin at snibworks dot com ---- I have made a new array function called array_split. It's like explode() for arrays. It searches the array for a specific value and splits the array into chunks divided by that value. <?php function array_split($key, $array) { if(!is_array($array))trigger_error("Invalid type provided for second parameter of array_split",E_USER_ERROR); $rarray = array(); $curkey = 0; foreach($array as $value) { if($value == $key) { $curkey++; continue; } $rarray[$curkey][] = $value; } return $rarray; } //an example $new_array = array('one','two','break','three', 'break','four','five','six'); var_dump(array_split('break',$new_array)); /*this returns: array(3) { [0]=> array(2) { [0]=> string(3) "one" [1]=> string(3) "two" } [1]=> array(1) { [0]=> string(5) "three" } [2]=> array(3) { [0]=> string(4) "four" [1]=> string(4) "five" [2]=> string(3) "six" } } */ ?>

« previous php.notes (#129815) next »