Ron Ron - 5 months ago 11
PHP Question

Find a string from group of string and take the value using php

we have a group of string like

white-1,black-2,blue-4
etc . This is the string format .

ie :
name1-name1 value , name2-name2 value
etc .

From this string i need to take the associated value . For example value of white is 1 , value of blue is 4 etc .

How can i do this ?

Answer
$result = array();

$combos = explode(',', $comboString);
foreach($combos as $string) {
    $parts = explode('-', trim($string));
    // $result[$part[0]] = $part[1];
    echo $parts[0] . ' => ' . $parts[1];
}

white will be set in $parts[0] and 1 will be set in $parts[1]

The commented line can be removed if every color only occurs ones, and you want to have a quick lookup table for it...