Created
November 26, 2010 18:08
-
-
Save damilare/717029 to your computer and use it in GitHub Desktop.
parse data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//loop to fetch members | |
function parse_data($str_to_array, $key = '', $value = '', $output_data = array()){ | |
foreach($str_to_array as $item){ | |
if(!is_numeric($item)){ | |
//check for values | |
if(!empty($key) && !empty($value)){ | |
$output_data[$key] = $value; | |
parse_data($str_to_array, '', '', $output_data); | |
} else { | |
$arg_key = $item; | |
array_shift($str_to_array); | |
parse_data($str_to_array, $arg_key, '', $output_data); | |
} | |
} elseif(is_numeric($item)) { | |
$value .= $item; | |
array_shift($str_to_array); | |
if(count($str_to_array) < 1){ | |
$output_data[$key] = $value; | |
var_dump($output_data); exit(); | |
return $output_data; | |
} else { | |
parse_data($str_to_array, $key, $value, $output_data ); | |
} | |
} | |
} | |
return $output_data; | |
} | |
$string = 'A8900A1B200C5D20E34F2'; | |
$str_to_array = str_split($string); | |
$output_data = parse_data($str_to_array); | |
var_dump($output_data); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment