I want to echo value from this array, so it'll say "true"
::object(stdClass)#25 (2) { ["Name"]=> string(3) "DPV" ["Value"]=> string(4) "true" }
How can I do this in PHP?
I want to echo value from this array, so it'll say "true"
::object(stdClass)#25 (2) { ["Name"]=> string(3) "DPV" ["Value"]=> string(4) "true" }
How can I do this in PHP?
Simply
<?php
echo $objectVarName->Value;
Note: $objectVarName
is not an array, it is an object.
A very common example of arrays in PHP as following:
$array = array(
"foo" => "bar",
"bar" => "foo",
);
assuming the object property of Value
is public ( which it is or it wouldn't be output ) you can use PHP's object operator ->
Such as:
echo $obj->Value;
In the case that it isn't public, you would want to use a get menthod, such as this
class obj{
protected $Value = true;
public function getValue(){
return $this->Value;
}
}
$obj = new obj();
echo $obj->getValue();
AS you can see both access the objects property the same basic way ( using the ->
). Which is different then how you access elements in an array. You can implement ArrayAccess on an object, which allows you to use it as if it was an array, but that's a post for another time.
Here is simple solution, might be helpful.
<?php
//Let suppose you have this array
$arr = array('id'=>1,'name'=>'alax','status'=>'true');
//Check out array (Basically return array with key and value).
print_r($arr);
// Get value from the particular index
echo "<br/>Your value is:".$arr['status'];
?>