-1

i have an array contain value like :

Check_Value ('level_codes', '1000', '1001','(1000,1002,1004)', 'DO ', '1')==1

i want to get values and store into an other parametrs like :

$codes = level_codes;
$first_value = 1000;
$second_value = 1001;
$list_values = (1000,1002,1004);
$action = DO;
$timer = 1;
$case = ==;
$status = 1;

is there any one please help me to do this work...!

4
  • 1
    Is the order always the same? Commented Jan 6, 2011 at 13:41
  • the above does not seems to be an array, more like passing lots of argument into a function? Commented Jan 6, 2011 at 13:51
  • Is Check_Value a name of array? Commented Jan 6, 2011 at 13:52
  • Check_Value is function name stored in database table as a string. Commented Jan 7, 2011 at 11:42

3 Answers 3

3

Use the list() function: http://php.net/list

Sign up to request clarification or add additional context in comments.

Comments

0

If the order is always the same, the following will reassign the values to the variables you want:

$parts = preg_split("/'?\(|\)'?/", $original_values);
$sub1 = explode(',', $parts[1]);
$codes = trim(str_replace("'", '', $sub1[0])) ;
$first_value = trim(str_replace("'", '', $sub1[1]));
$second_value = trim(str_replace("'", '', $sub1[2]));
$list_values = "($parts[2])";
$sub2 = explode(',', $parts[3]);
$action = trim(str_replace("'", '', $sub2[1]));
$timer = trim(str_replace("'", '', $sub2[2]));
preg_match('/(\D+)(\d+)/', $parts[4], $matches);
$case = $matches[1];
$status = $matches[2];

There might be a more elegant way to do it, but the original value is a string, rather than an array.

Comments

0

If the array is string, i think you should look into preg_match

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.