Display Object data if parameters not definedHow do I compare two DateTime objects in PHP 5.2.8?How do I get PHP errors to display?Object Oriented PHP Best Practicesdefine() vs constAre PHP5 objects passed by reference?mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc… expects parameter 1 to be resource or resultHow does PHP 'foreach' actually work?How can I override a DI container dependency with a specific instance?PayPal ignoring return url if it includes parametersAccessing PHP Objects
Should I join office cleaning event for free?
What are these boxed doors outside store fronts in New York?
What is the offset in a seaplane's hull?
Can I interfere when another PC is about to be attacked?
"which" command doesn't work / path of Safari?
What exactly is the parasitic white layer that forms after iron parts are treated with ammonia?
How do I create uniquely male characters?
How to re-create Edward Weson's Pepper No. 30?
declaring a variable twice in IIFE
How is this relation reflexive?
Prevent a directory in /tmp from being deleted
Is it possible to make sharp wind that can cut stuff from afar?
Is there really no realistic way for a skeleton monster to move around without magic?
How can the DM most effectively choose 1 out of an odd number of players to be targeted by an attack or effect?
Download, install and reboot computer at night if needed
How to add power-LED to my small amplifier?
Motorized valve interfering with button?
Is it tax fraud for an individual to declare non-taxable revenue as taxable income? (US tax laws)
Draw simple lines in Inkscape
Do airline pilots ever risk not hearing communication directed to them specifically, from traffic controllers?
Why doesn't Newton's third law mean a person bounces back to where they started when they hit the ground?
Accidentally leaked the solution to an assignment, what to do now? (I'm the prof)
Are tax years 2016 & 2017 back taxes deductible for tax year 2018?
How does one intimidate enemies without having the capacity for violence?
Display Object data if parameters not defined
How do I compare two DateTime objects in PHP 5.2.8?How do I get PHP errors to display?Object Oriented PHP Best Practicesdefine() vs constAre PHP5 objects passed by reference?mysql_fetch_array()/mysql_fetch_assoc()/mysql_fetch_row()/mysql_num_rows etc… expects parameter 1 to be resource or resultHow does PHP 'foreach' actually work?How can I override a DI container dependency with a specific instance?PayPal ignoring return url if it includes parametersAccessing PHP Objects
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
So let's say I want to display name inside object, That would be
echo $object->name
If I want to display age of specific person, that would be
echo $object->name->dave->age
And I can display a lot of things.
However, What should I do if I don't know parameters which to display?
So let's say dave passed to me, and right now in $person
That would be something like
echo $object->name->$person->age
However I can't do that.
Is there any way to do that?
php
add a comment |
So let's say I want to display name inside object, That would be
echo $object->name
If I want to display age of specific person, that would be
echo $object->name->dave->age
And I can display a lot of things.
However, What should I do if I don't know parameters which to display?
So let's say dave passed to me, and right now in $person
That would be something like
echo $object->name->$person->age
However I can't do that.
Is there any way to do that?
php
Need more detail, your question is not clear.
– Ankur Tiwari
Mar 8 at 5:48
1
$object->name->agemakes no sense. Are you fetching the age of the name? If you want that format thennameneeds to be an object with a__toString()function that returns the name if it is cast as a string. Thename-object would also need to have anage-property. A more sensible structure would be to have$obj->nameand then$obj->age.
– Magnus Eriksson
Mar 8 at 5:53
Define a magic__getmethod on your classes. See php.net/manual/language.oop5.overloading.php#object.get and more generally php.net/manual/language.oop5.magic.php
– Phil
Mar 8 at 5:56
Nah, if you have$object->name->dave, then you are seriously doing OO wrong …
– 04FS
Mar 8 at 8:30
@04FS That's what I'm getting from API to my request.
– Rostyslav
Mar 8 at 8:36
add a comment |
So let's say I want to display name inside object, That would be
echo $object->name
If I want to display age of specific person, that would be
echo $object->name->dave->age
And I can display a lot of things.
However, What should I do if I don't know parameters which to display?
So let's say dave passed to me, and right now in $person
That would be something like
echo $object->name->$person->age
However I can't do that.
Is there any way to do that?
php
So let's say I want to display name inside object, That would be
echo $object->name
If I want to display age of specific person, that would be
echo $object->name->dave->age
And I can display a lot of things.
However, What should I do if I don't know parameters which to display?
So let's say dave passed to me, and right now in $person
That would be something like
echo $object->name->$person->age
However I can't do that.
Is there any way to do that?
php
php
edited Mar 8 at 7:58
Rostyslav
asked Mar 8 at 5:47
RostyslavRostyslav
366
366
Need more detail, your question is not clear.
– Ankur Tiwari
Mar 8 at 5:48
1
$object->name->agemakes no sense. Are you fetching the age of the name? If you want that format thennameneeds to be an object with a__toString()function that returns the name if it is cast as a string. Thename-object would also need to have anage-property. A more sensible structure would be to have$obj->nameand then$obj->age.
– Magnus Eriksson
Mar 8 at 5:53
Define a magic__getmethod on your classes. See php.net/manual/language.oop5.overloading.php#object.get and more generally php.net/manual/language.oop5.magic.php
– Phil
Mar 8 at 5:56
Nah, if you have$object->name->dave, then you are seriously doing OO wrong …
– 04FS
Mar 8 at 8:30
@04FS That's what I'm getting from API to my request.
– Rostyslav
Mar 8 at 8:36
add a comment |
Need more detail, your question is not clear.
– Ankur Tiwari
Mar 8 at 5:48
1
$object->name->agemakes no sense. Are you fetching the age of the name? If you want that format thennameneeds to be an object with a__toString()function that returns the name if it is cast as a string. Thename-object would also need to have anage-property. A more sensible structure would be to have$obj->nameand then$obj->age.
– Magnus Eriksson
Mar 8 at 5:53
Define a magic__getmethod on your classes. See php.net/manual/language.oop5.overloading.php#object.get and more generally php.net/manual/language.oop5.magic.php
– Phil
Mar 8 at 5:56
Nah, if you have$object->name->dave, then you are seriously doing OO wrong …
– 04FS
Mar 8 at 8:30
@04FS That's what I'm getting from API to my request.
– Rostyslav
Mar 8 at 8:36
Need more detail, your question is not clear.
– Ankur Tiwari
Mar 8 at 5:48
Need more detail, your question is not clear.
– Ankur Tiwari
Mar 8 at 5:48
1
1
$object->name->age makes no sense. Are you fetching the age of the name? If you want that format then name needs to be an object with a __toString() function that returns the name if it is cast as a string. The name-object would also need to have an age-property. A more sensible structure would be to have $obj->name and then $obj->age.– Magnus Eriksson
Mar 8 at 5:53
$object->name->age makes no sense. Are you fetching the age of the name? If you want that format then name needs to be an object with a __toString() function that returns the name if it is cast as a string. The name-object would also need to have an age-property. A more sensible structure would be to have $obj->name and then $obj->age.– Magnus Eriksson
Mar 8 at 5:53
Define a magic
__get method on your classes. See php.net/manual/language.oop5.overloading.php#object.get and more generally php.net/manual/language.oop5.magic.php– Phil
Mar 8 at 5:56
Define a magic
__get method on your classes. See php.net/manual/language.oop5.overloading.php#object.get and more generally php.net/manual/language.oop5.magic.php– Phil
Mar 8 at 5:56
Nah, if you have
$object->name->dave, then you are seriously doing OO wrong …– 04FS
Mar 8 at 8:30
Nah, if you have
$object->name->dave, then you are seriously doing OO wrong …– 04FS
Mar 8 at 8:30
@04FS That's what I'm getting from API to my request.
– Rostyslav
Mar 8 at 8:36
@04FS That's what I'm getting from API to my request.
– Rostyslav
Mar 8 at 8:36
add a comment |
1 Answer
1
active
oldest
votes
You can loop through object like this,
foreach ($object as $key => $value)
echo "$key => $valuen";
Also you can check if the variable is object or not using ,
is_object($object);
is_object()
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55057403%2fdisplay-object-data-if-parameters-not-defined%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can loop through object like this,
foreach ($object as $key => $value)
echo "$key => $valuen";
Also you can check if the variable is object or not using ,
is_object($object);
is_object()
add a comment |
You can loop through object like this,
foreach ($object as $key => $value)
echo "$key => $valuen";
Also you can check if the variable is object or not using ,
is_object($object);
is_object()
add a comment |
You can loop through object like this,
foreach ($object as $key => $value)
echo "$key => $valuen";
Also you can check if the variable is object or not using ,
is_object($object);
is_object()
You can loop through object like this,
foreach ($object as $key => $value)
echo "$key => $valuen";
Also you can check if the variable is object or not using ,
is_object($object);
is_object()
answered Mar 8 at 5:56
Shoyeb SheikhShoyeb Sheikh
607211
607211
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55057403%2fdisplay-object-data-if-parameters-not-defined%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Need more detail, your question is not clear.
– Ankur Tiwari
Mar 8 at 5:48
1
$object->name->agemakes no sense. Are you fetching the age of the name? If you want that format thennameneeds to be an object with a__toString()function that returns the name if it is cast as a string. Thename-object would also need to have anage-property. A more sensible structure would be to have$obj->nameand then$obj->age.– Magnus Eriksson
Mar 8 at 5:53
Define a magic
__getmethod on your classes. See php.net/manual/language.oop5.overloading.php#object.get and more generally php.net/manual/language.oop5.magic.php– Phil
Mar 8 at 5:56
Nah, if you have
$object->name->dave, then you are seriously doing OO wrong …– 04FS
Mar 8 at 8:30
@04FS That's what I'm getting from API to my request.
– Rostyslav
Mar 8 at 8:36