0

How can I extract data from this array:

Array
(
 [0] => Array
 (
 [name] => color / size 
 [value] => Array
 (
 [0] => blue / l 
 [1] => blue / m 
 [2] => red / l 
 [3] => red / m 
 )
}

in this format?

color = blue,red
size = L,M
Al.G.
4,4476 gold badges35 silver badges63 bronze badges
asked Apr 11, 2017 at 5:50
1
  • show how should look the whole final array Commented Apr 11, 2017 at 5:55

1 Answer 1

1

Using implode() and explode() will solve the purpose. Try this:

foreach ($array[0]['value'] as $k => $val) {
 $values = explode(' / ', $val); // Break up string into array
 $color[] = $values[0]; // Store colors in this array
 $size[] = $values[1]; // Store size in this array
}
echo 'Color = ' . implode(',', array_unique($color)); // First get unique values using array_unique, then convert this array to string using implode()
echo '<br/>';
echo 'Size = '. implode(',', array_unique($size)); // First get unique values using array_unique, then convert this array to string using implode()
Rahul
18.6k7 gold badges43 silver badges64 bronze badges
answered Apr 11, 2017 at 5:59
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.