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 8248805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:19:17+00:00 2026-06-07T23:19:17+00:00

I am probably missing something simple here but I feel it best to ask

  • 0

I am probably missing something simple here but I feel it best to ask anyway.

I have the following code:

$newarray = json_decode($jsoncode);
$rad = 24;
foreach ($newarray->objname as $obj)
{
    echo "<map name='" . $mapname . "'>";
    echo "<area shape=\"circle\" coords='" . $obj->x . "," . $obj->y . "," . $rad . "' alt='" . $obj . "'>";
    echo '</map>';
}

coming from a manually created json string:

$jsoncode = '{"objname":{"Forest 1":{"x":120,"y":120},"Forest 2":{"x":434,"y":225}}}';

I am getting an error when trying to call the $obj variable to use within the foreach. Is there like something I have to add to make it show the name stored in the variable?

P.S. I have no problem with the rest of the code

  • 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-07T23:19:20+00:00Added an answer on June 7, 2026 at 11:19 pm

    PHP’s foreach syntax should be like this –

    foreach ($array AS $key=>$object){ 
      ... 
    }
    

    So your code should look like this –

    foreach ($newarray AS $objectName => $obj)
    
    • $objectName is the index in $newarray.
    • $obj is the actual element from the array.

    http://php.net/manual/en/control-structures.foreach.php

    The documentation has this to say about the syntax of the foreach statement –

    foreach (array_expression as $value)
    statement
    foreach (array_expression as $key => $value)
    statement

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

Sidebar

Related Questions

I am probably missing something very simple, but here is the situation: I have
Sorry, I'm probably missing something simple here, but I feel like I've tried everything.
I have a feeling I'm missing something pretty simple here but, in this one
I'm probably missing something simple, but ListRows.Add is giving me grief. Here's the function:
Okay, I'm probably missing something really simple here, but I've been at this for
I'm probably missing something easy, but I seem to be blocked here... I have
I probably am missing something very simple here, but I cannot see it. MSAccess
I'm probably missing something simple here, but I can't find the answer elsewhere. I
I'm probably missing something simple here, but I'm having trouble with the jquery ui
I'm probably missing something very simple here, but please bear with me. What I

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.