Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8234437
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:28:35+00:00 2026-06-07T18:28:35+00:00

i have an Array , when i print it i get the following output;

  • 0

i have an Array, when i print it i get the following output;

Array[{"city":"London","school":"st patrick"}]

Now i want to read the item saved in variable city and check if its London in the IF condition below;

if ($cityArray['city'] == 'London') {

  echo 'City present';
}

My if condition above, is incorrect, i am not getting the expected output. I guess the way i am accessing the city item is incorrect.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T18:28:37+00:00Added an answer on June 7, 2026 at 6:28 pm

    A couple of things. Your array looks to be JSON format. You’ll want to decode using json_decode (after fixing the format of the array):

    $jsonArray = Array('{"city":"London","school":"st patrick"}'); // User the correct PHP array format: Array() while the inside elements should be quoted if they're strings.
    $cityArray = json_decode($jsonArray[0]);
    

    Use the correct variable reference format:

    if ($cityArray->city == 'London') { // $cityArray is an object, so you'll need to use the -> operator to get its "city" property.
        echo 'City present';
    }
    

    The way you’re trying to access the value of the associative array (by inputting the name to return the value) is correct, but just need to fix a couple of formatting issues, is all.

    Edit: Added index number of array to get the JSON.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a two-dimensional array. When I print/dump this I get the following My
I have an array in Perl I want to print with space delimiters between
I have an array of numbers: @numbers = 1,2,3,6,8,9,11,12,13,14,15,20 and I want to print
I have a php code that gives me the following output: (its an array)
I have an Array , if I print that in console it shows Price
I have an array of double pointers, but every time I try do print
Background: Suppose I have the following obviously-incorrect PHP: try{ $vtest = ''; print(array_pop($vtest)); }catch(Exception
I have an double array alist[1][1]=-1 alist2=[] for x in xrange(10): alist2.append(alist[x]) alist2[1][1]=15 print
I have written a function to print database table to an array like this
I currently have the following javascript array: var stuffs = ['a', 'b']; I pass

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.