1

i have tried this script and the result is true

$a = array('Allow','Block');
$b = array('yes','no');
$c=array_combine($a,$b);

while (list($key, $value) = each($c)) {
echo "$key: $value \n";
}

the true result :

Allow:yes Block:no

but when i use a varible into the array

$val1 = "'Allow','Block'";
$val2 = "'yes','no'";
$a = array($val1);
$b = array($val2);

the result is different :

'Allow','Block': 'yes','no'

the question is how i can make the first result because i got the text from dynamic varible

1
  • 2
    using of variable there, considers a single dimension's value there. you need to utilize different values separating with commas.. Commented Jan 30, 2016 at 19:57

4 Answers 4

2

You can't use arrays like in second example. You should probably try something like this:

$val1 = "Allow,Block";
$val2 = "yes,no";
$a = explode(',',$val1);
$b = explode(',', $val2);
Sign up to request clarification or add additional context in comments.

Comments

1

You can also get the true result by using the simple foreach like:

$a = array('Allow','Block'); 
$b = array('yes','no');

$trueResult = array();
foreach($a as $key => $value){
   $trueResult[$value] = $b[$key];
}

foreach($trueResult as $key => $val){
  echo $key . "=". $val."<br>";
}

Comments

1

Try following code.

$val1 = "Allow,Block";
$val2 = "yes,no";
$a = explode(',',$val1);
$b = explode(',', $val2);
$c=array_combine($a,$b);

while (list($key, $value) = each($c)) {
    echo "$key: $value \n";
}

1 Comment

Sorry dude long time to replay, this forum very helpful. i can't resolved my proble in google search. Because i just stupuid script kiddie... Thanks guys you save my day :D those answer are working!
1
$val1 = "'Allow','Block'";
$val2 = "'yes','no'";

$val1 = str_replace("'", "", $val1);
$val2 = str_replace("'", "", $val2);
$c = array_combine(explode(',', $val1), explode(',', $val2));

while (list($key, $value) = each($c)) {
    echo "$key: $value \n";
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.