PHP - Exploding each item in an array created by explode -


my code is...

$string ="foo:bar,bar,bar|foo2:bar2,bar2,bar2";  $first_array = explode("|", $string);  function split(&$block) {  $block = explode(":", $block);  }  array_walk($first_array, "split");  echo $block["0"]["0"]; echo "<br />"; echo $block["0"]["1"];  ?> 

thank far. i've gathered should clean version of supplied code. not echo anything, , neither code supplied.

this trick:

$string ="foo:bar:bar:bar|foo2:bar2:bar2:bar2";  // first explode on | $first_array = explode("|", $string); // function go on each lines of array , transform each function array_walk($first_array, function(&$item) {          // each line explode ':' delimiter          $item = explode(':', $item); });  // check lines of array foreach($first_array $line_array) {      //my code each sub-array }  // last (second) $second_sub = array_pop($first_array);  // if want 1 dimension exploded can use // function split regexp pattern // "/[\|:,]+/" foreach "|" or ":" or ","  split string preg_split("/[\|:,]+/", $string); 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -