3

Here is the code I have now.

$Top3Things = explode(';',$Top3Things);
foreach($Top3Things as $key => $Thing)
    $Top3Things[$key] = explode('|',$Thing);

I know that explode return an indexed array. But I thought there is a function I can put explode into and pass the names that will return an associative array.

I know this is not the answer but here is an example of what I'm looking for.

$Top3Things[$key] = (list($type,$size,$weight) = explode('|',$Thing));

1 Answer 1

4

The function you're looking for is array_combine().

<?php
$keys = ['type', 'size', 'weight'];
$values = explode(';', $Top3Things);
$combinedArray = array_combine($keys, $values);
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks, I feel better now.

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.