Access array returned by a function in php

phparrayfunctionreturnreturnedaccess

Last Update : 2023-09-22 UTC 11:27:14 AM

Answers of > Access array returned by a function in php

$this->data is always accessible, if it is w3coded array returned protected. $object->data is not accessible from w3coded array returned everywhere, so if you're returning $this in your w3coded array returned code, and it is evaluated as such, it should be w3coded array returned ok., w3coded array returned w3coded array returned How is (was) that string value that you w3coded array returned return in myfunction() processed further? That w3coded array returned part is missing in your question. w3coded array returned – hakre w3coded array returned Jul 13 '13 at 9:46 w3coded array returned ,If you don't want a temporary variable w3coded array returned for that and your PHP version is less, than 5.4, w3coded array returned than you still can use a few built in functions w3coded array returned to get the first or the last element:, w3coded array returned w3coded array returned What are w3coded array returned you trying to check? Do you try to see if the w3coded array returned array element exists and has a non-empty value? w3coded array returned You can use the function 'empty' for this. This w3coded array returned question needs more clarity! w3coded array returned – txwikinger w3coded array returned Sep 22 '09 at 13:18 w3coded array returned

Since PHP 5.4 it's possible to do exactly that:

getSomeArray()[2]

You cannot use something like this :

$this->getData()['a']['b']

Youy have to use some temporary variable, like this :

$tmp = $this->getData();
$tmp['a']['b']    // use $tmp, now

In your case, this probably means using something like this :

function myfunction() {
  $tmp = $this->getData();
  return ($tmp['a']['b'] ? true : false);
}

I created the function:

arrayGet($array, $index) { return $array[$index]; }

And used it like this:

myfunction() { return '(arrayGet(arrayGet($this, "a"), "b") ? true : false)' }

Btw, there is a bug in your code: The quotes need to be escaped.

myfunction() { return '($this->data[\'a\'][\'b\'] ? true : false)'; }

If you don't want a temporary variable for that and your PHP version is less, than 5.4, than you still can use a few built in functions to get the first or the last element:

$x     = 'first?last';
$first = array_shift(explode('?', $x));
$last  = end(explode('?', $x));
$last2 = array_pop(explode('?', $x));

Current topics : Access array returned by a function in php

Newly Added Questions

Similar Questions

Questions :

How To Group Array Key Value

Last Update : 2023-09-22 UTC 12:58:52 PM

Questions :

PhpStorm Warning For React Attributes In Jsx File With SCSS File

Last Update : 2023-09-22 UTC 12:58:37 PM

Questions :

Why Is The File Not Showing Up In Request.files And In Request.forms Instead?

Last Update : 2023-09-22 UTC 12:58:23 PM

Questions :

Proxying Assets From React App Directory In Slim Framework?

Last Update : 2023-09-22 UTC 12:58:16 PM

Questions :

Laravel 5.4 Can't Run “php Artisan Preset React” Comand

Last Update : 2023-09-22 UTC 12:58:08 PM

Questions :

How To Update Session Values Without Signing Out?

Last Update : 2023-09-22 UTC 12:58:03 PM

Questions :

Array Is Not Visible

Last Update : 2023-09-22 UTC 12:57:44 PM

Questions :

React Routing For Login Using Symfony

Last Update : 2023-09-22 UTC 12:57:27 PM

Questions :

Sanctum With React SPA Returning 419 Page Expired

Last Update : 2023-09-22 UTC 12:57:20 PM

Questions :

How Do I Import An Input String Into Another Page

Last Update : 2023-09-22 UTC 12:57:09 PM

Top
© 2023 W3CODED - All Rights Reserved.