I have a multidimensinal array.. Something like this for example:
Array ( [0] => Array ( [title] => Star Trek - Viaje a las estrellas [country] => Venezuela, Spain, long title, poster title ) [1] => Array ( [title] => Viaje a Las Estrellas [country] => Venezuela ) )
I want to get te text between commas from [country] and insert each element into separate indexes, for example:
Array ( [0] => Array ( [title] => Star Trek - Viaje a las estrellas [country] => [0] => Venezuela [1] => Spain [2] => long title [3] => poster title ) [1] => Array ( [title] => Viaje a Las Estrellas [country] => Venezuela ) )
Probably the array layout is incorrect but I just want to explain to you what I need to do. Note that not always [country] contains elements separated by commas, sometimes is just one single element.
How can I do it??
Thanks!
Try using
explode()on the country element. You can use a separator of', ', since these are comma-separated values.One way to do it (which is similar to how others have suggested) would be:
Also, note that you don’t really need to use
strpos()—strstr()works perfectly here.