1

I am working with an array that sometimes has a multidimensional array. I am trying to accomplish making this array into a single line array.

Array
(
    [0] => Array
        (
            [attribute_code] => 203
            [attribute_value] => Array
                (
                    [0] => 24214
                )

        )

    [1] => Array
        (
            [attribute_code] => 252
            [attribute_value] => Array
                (
                    [0] => 22865
                    [1] => 25086
                )

        )

)

This is what I am trying to accomplish

Array
(
    [0] => {"attribute_code":"203","attribute_value":"24214"}
    [1] => {"attribute_code":"252","attribute_value":["22865","25086"]}
)

What would the best way to accomplish this?

0

1 Answer 1

1

That is just JSON encoding each element:

$result = array_map("json_encode", $array);
Sign up to request clarification or add additional context in comments.

2 Comments

You could reduce this to $result = array_map("json_encode", $array);
@NigelRen: Thanks, it's been an overthinking stuff kind of day ;-)

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.