Parsing arrays in PHP [closed]

General Tech Bugs & Fixes 2 years ago

0 1 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (1)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I am developing a PHP application and I have the following array: print_r($array)

Array (
    [0] => stdClass Object (
        [can_see_custom_stories] => 1
        [name] => caitlinhamm
        [display] =>
        [type] => 3
    )
    [1] => stdClass Object (
        [can_see_custom_stories] => 1
        [name] => vladhq
        [display] =>
        [type] => 0
    )
    [2] => stdClass Object ( [can_see_custom_stories] => 1 [name] => interne [display] => Vlad [type] => 0 )
    [3] => stdClass Object ( [can_see_custom_stories] => 1 [name] => frankiedoyle30 [display] => [type] => 0 )
    [4] => stdClass Object ( [can_see_custom_stories] => 1 [name] => ayyeitskenzie03 [display] => [type] => 0 )
    [5] => stdClass Object ( [can_see_custom_stories] => 1 [name] => laynedawwg [display] => Layne [type] => 0 )
    [6] => stdClass Object ( [can_see_custom_stories] => 1 [name] => sarah.murphy225 [display] => [type] => 1 )
    [7] => stdClass Object ( [can_see_custom_stories] => 1 [name] => rath1 [display] => Rathwaan [type] => 0 )
    [8] => stdClass Object ( [can_see_custom_stories] => 1 [name] => brittanyyo [display] => Brit [type] => 0 )
    [9] => stdClass Object ( [can_see_custom_stories] => 1 [name] => teamsnapchat [display] => Snapchat [type] => 0 )
    [10] => stdClass Object ( [can_see_custom_stories] => 1 [name] => falconpunch1209 [display] => Colin Parker [type] => 0 )
    [11] => stdClass Object ( [can_see_custom_stories] => 1 [name] => shawn_bonds [display] => Shawn Bonds [type] => 0 )
    [12] => stdClass Object ( [can_see_custom_stories] => 1 [name] => chrisknowles [display] => Chris [type] => 0 )
    [13] => stdClass Object ( [can_see_custom_stories] => 1 [name] => pypereronipizza [display] => [type] => 0 )
    [14] => stdClass Object ( [can_see_custom_stories] => 1 [name] => wannaknow123 [display] => [type] => 0 )
    [15] => stdClass Object ( [can_see_custom_stories] => 1 [name] => zainthugmalik [display] => Zain [type] => 1 )
    [16] => stdClass Object ( [can_see_custom_stories] => 1 [name] => quinlanjade [display] => Quin [type] => 1 )
)

I want to pass it some how easily without any of the foreach() statements.

So the array is $snapchat->getFriends(). Is it possible for me to do something like:

$user = 'shawn_bonds';
$display = $snapchat->getFriends()->name['shawn_bonds']->display;

How would I get a display name based on the original name?

Thanks!

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community