Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function array_build(&$output, &$array, $indent){
- $output .= 'array(';
- $i = 0;
- foreach($array as $key => $val){
- if(is_string($key)){
- $output .= '\'' . $key . '\' => ';
- }
- if(is_array($val)){
- array_build($output, $array[$key], $indent++);
- }else{
- // Is the value a string, if so quote it.
- if(is_string($val)){
- // Are we on the last iteration.
- if($i !== count($array) - 1){
- // Nope, comma seperate.
- $output .= '\'' . $val . '\', ';
- }else{
- // Yep, no comma.
- $output .= '\'' . $val . '\'';
- }
- }else{
- // Are we on the last iteration.
- if($i !== count($array) - 1){
- // Nope, comma seperate.
- $output .= $val . ', ';
- }else{
- // Yep, no comma.
- $output .= $val;
- }
- }
- }
- // Increment i, check if we are on the last iteration.
- ++$i;
- }
- $output .= ')';
- // Place a comma after all parent level elements.
- if($indent === 1){
- $output .= ', ';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement