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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T10:54:46+00:00 2026-05-27T10:54:46+00:00

i have this data cennik.json file: { waluta: PLN, vat: 1.23, 00101: { cena:

  • 0

i have this data cennik.json file:

{
    "waluta": "PLN",
    "vat": 1.23,
    "00101": {
        "cena": 340,
        "powiazanyZ": "00139"
    },
    "00102": {
        "cena": 325.33,
        "powiazanyZ": "00140"
    },
    "00103": {
        "cena": 306.67,
        "powiazanyZ": "00141"
    },
    "00104": {
        "cena": 289.33,
        "powiazanyZ": "00142"
    },
    "00105": {
        "cena": 276,
        "powiazanyZ": "00143"
    },
    "00106": {
        "cena": 258.67,
        "powiazanyZ": "00144"
    },
    "00107": {
        "cena": 240,
        "powiazanyZ": "00145"
    },
    "00108": {
        "cena": 222.67,
        "powiazanyZ": "00146"
    },
    "00109": {
        "cena": 205.33,
        "powiazanyZ": "00147"
    },
    "00110": {
        "cena": 189.33,
        "powiazanyZ": "00148"
    },
    "00120": {
        "cena": 413.33,
        "powiazanyZ": "00150"
    },
    "00121": {
        "cena": 73.33,
        "powiazanyZ": "00000"
    },
    "00122": {
        "cena": 153.33,
        "powiazanyZ": "00000"
    },
    "00123": {
        "cena": 153.33,
        "powiazanyZ": "00000"
    },
    "00138": {
        "cena": 1937,
        "powiazanyZ": "00152"
    },
    "00139": {
        "cena": 366.82,
        "powiazanyZ": "00101"
    },
    "00140": {
        "cena": 325.33,
        "powiazanyZ": "00102"
    },
    "00141": {
        "cena": 306.67,
        "powiazanyZ": "00103"
    },
    "00142": {
        "cena": 289.33,
        "powiazanyZ": "001041"
    },
    "00143": {
        "cena": 276,
        "powiazanyZ": "00105"
    },
    "00144": {
        "cena": 258.67,
        "powiazanyZ": "00106"
    },
    "00145": {
        "cena": 240,
        "powiazanyZ": "00107"
    },
    "00146": {
        "cena": 222.67,
        "powiazanyZ": "00108"
    },
    "00147": {
        "cena": 205.33,
        "powiazanyZ": "00109"
    },
    "00148": {
        "cena": 189.33,
        "powiazanyZ": "00110"
    },
    "00150": {
        "cena": 413.33,
        "powiazanyZ": "00120"
    },
    "00152": {
        "cena": 1997.33,
        "powiazanyZ": "00138"
    }
}

and this from my php file:

$vat = 0.00;
$waluta = '';
$kod00101 = 0.00;
$kod00102 = 0.00;
...
$kod00152 = 0.00;

$cennik_plik = file_get_contents("cennik.json");
$jsonIterator = new RecursiveIteratorIterator(
    new RecursiveArrayIterator(json_decode($cennik_plik, TRUE)),
    RecursiveIteratorIterator::SELF_FIRST);

foreach ($jsonIterator as $key => $val) {
    if(is_array($val)) {
        $v = ${'kod'.$key};
        if('$key' == $v){
            $v = number_format((float)$val[cena],2,'.','');
        }
    } else {
        if('$key' == 'waluta') {$waluta = $val;};
        if('$key' == 'vat') {$vat = number_format((float)$val,2,'.','');};
    }
}

i am trying this and i get following error:

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Passed variable is not an array or object, using empty array instead' in C:\Documents and Settings\user\Desktop\Lighty2Go\HTDOCS\ogr\index.php:50
Stack trace:
 #0 C:\Documents and Settings\user\Desktop\Lighty2Go\HTDOCS\ogr\index.php(50): ArrayIterator->__construct('???{?? "walu...')
 #1 {main} thrown in C:\Documents and Settings\user\Desktop\Lighty2Go\HTDOCS\ogr\index.php on line 50

Any Suggestions?

I have tried to solve it myself using these resources, but nothing:

  • Parsing JSON file with PHP
  • Parsing this JSON file structure
  • 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-05-27T10:54:47+00:00Added an answer on May 27, 2026 at 10:54 am

    I’m not quite sure what you are attempting with that data. But you certainly don’t need that RecursiveArrayIterator. A boring foreach is enough to traverse that array:

    $json = file_get_contents("cennik.json");
    # the culprit was the UTF-8 BOM, which OPs specific verison of json_decode tripped over (newer versions would return NULL)
    $json = preg_replace('/^\xEF\xBB\xBF/', '', $json);
    $array = json_decode($json, TRUE);
    
    var_dump($array);    # <-- WHAT DOES THAT OUTPUT ??
    
    
    foreach ($array as $key => $value) {
    
        if ($key == "waluta") {
            $waluta = $value;
        }
        elseif ($key == "vat") {
            $vat = $value;
        }
    
        // all the data entries
        elseif (is_numeric($key)) {
            $kod[$key] = $value["cena"];
            // ${"kod$key"} = ...;
        }
    }
    

    Note that you can use variable variables. But this example screams array. I’m not even sure why you would want to use a separate list of variables. The source array should be good enough to work with.

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

Sidebar

Related Questions

I have this data from a xml file: <?xml version=1.0 encoding=utf-8 ?> <words> <id>...</id>
Basically I have an XML file that looks like this: <?xml version=1.0 encoding=UTF-8?> <data>
I have this data file, which is supposed to be a normal ASCII file.
I have this following JSON data snippit: {items: [ { title: sample 1, author:
I have this data in cell A1: Majestic Properties Design District, LLC, Ste. 101,
i have this data | car_name | year | price | Honda | 2011
I have this data: /blabla/blabla (abs,def) /yxz I use this regex (.*)(?:\(([^$]*)\))?\n But it
I have this data: 1, 0., 0., 1500. . . 21, 0., 2000., 1500.
I have this data in a table, for instance, id name parent parent_id 1
Let say if I have this data my_data = [ 10 20 30 40;

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.