Answers for "how to lookup value inside object php"

PHP
1

array_search

// array demo

public $gender = array(
  1 => 'Male',
  2 => 'Female',
  3 => 'Other',
);

$gen = 1;

if ($gen == array_search('Male', $this->gender)) {
  $gender = __d('member', 'male');

} elseif ($gen  == array_search('Female', $this->gender)) {
  $gender = __d('member', 'female');

}
Posted by: Guest on October-02-2020
0

how to lookup value inside object php

$array = [
    'clothes' => 't-shirt',
    'size'    => 'medium',
    'color'   => 'blue',
];
 
extract($array);
 
echo("$clothes $size $color"); // t-shirt medium blue
Posted by: Guest on October-30-2020
0

how to lookup value object php

$fruit = json_decode($fruit, true);
lookup($fruit, 'key');
Posted by: Guest on October-30-2020
0

how to lookup value object php

function lookup($array, $key) {

    //loop through all values in array
    foreach($array as $values) {

        //if 'key' value matches `$key`, return 'value' value.
        if($values['key'] == $key) {
            return $values['value'];
        }

    }

    //if nothing has been returned, return empty string
    return "";
}
Posted by: Guest on October-30-2020

Code answers related to "how to lookup value inside object php"

Browse Popular Code Answers by Language