return only the content from an array (access key) in php

  arrays, php

I’m trying to only get the Content from an array back without the access key.

I have the following function

protected static function getContent()    {
    $title = $storage->getTransUnitById($dive->getScenario()->getTitle());
    $text = $storage->getTransUnitById($dive->getScenario()->getText());
    $additionalText = $storage->getTransUnitById($dive->getScenario()->getAdditionalText());
    $buttonText = $storage->getTransUnitById($dive->getScenario()->getButtonText());

    $result = null;

    $result['title'] = $title instanceof TransUnit ?
        $title->getTranslation($locale)->getContent() :
        null;
    $result['text'] = $text instanceof TransUnit ?
        $text->getTranslation($locale)->getContent() :
        null;
    $result['additionalText'] = $additionalText instanceof TransUnit ?
        $additionalText->getTranslation($locale)->getContent() :
        null;
    $result['buttonText'] = $buttonText instanceof TransUnit ?
        $buttonText->getTranslation($locale)->getContent() :
        null;

    return $result;
}

Which i use like so

     'scenario' => [
            self::getContent($storage, $dive, $locale),
            'image' => array_key_exists('scenario', $pathing) ? $pathing['scenario'] : null
        ],

The Problem is I get the following output

            "scenario": {
            "0": {
                "title": "test",
                "text": "test",
                "additionalText": "test",
                "buttonText": "test"
            },
            "image": "http://test.local/images/test.png"
        },

What I would want is not to have the array index. Like so

            "scenario": {
                "title": "test",
                "text": "test",
                "additionalText": "test",
                "buttonText": "test"
                "image": "http://test.local/images/test.png"
        },

How can i achieve this result ?
I’m unsure – or maybe im overthining this

Source: Ask PHP

LEAVE A COMMENT