0

I have two arrays, one is generated by using explode() on a comma separated string and the other is generated from result_array() in Codeigniter.

The results when doing print_r are:

From explode():

Array
(
    [0] => keyword
    [1] => test
)

From database:

Array
(
    [0] => Array
        (
            [name] => keyword
        )

    [1] => Array
        (
            [name] => test
        )
)

I need them to match up so I can use array_diff(), what's the best way to get them to match? Is there something other than result_array() in CI to get a compatible array?

1
  • foreach $db_array as ($key => $val) { $db_array[$key] = $db_array[$key]['name']; }? Commented Aug 2, 2012 at 17:01

2 Answers 2

1

You could create a new array like this:

foreach($fromDatabase as $x)
{
  $arr[] = $x['name'];
}

Now, you will have two one dim arrays and you can run array_dif.

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

Comments

0
$new_array = array();
foreach ($array1 as $line) {
   $new_array[] = array('name' => $line);
}
print_r($new_array);

That should work for you.

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.