Jump to content

akaweed

New Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Everything posted by akaweed

  1. A php array is equivalent to a C structure. php arrays are not defined by intrinsic types, and are addressable by keys, which are the main reasons to use structures in C. Just my opinion...
  2. hey guys, I apologize, as this stuff should be easy to figure out, but I am getting stumped again being a php rookie. I have searched a lot for an answer before I bothered you all. Here's the skinny: I have a string coming in via post content that looks like: name1\x1ddata1\x1ename2\x1ddata2\x1e ... where the delimiters are 0x1e for the field/data pairs and 0x1d between the field/data . there may be as many as 20 of these pairs in the string. I have the string and I can store the pairs with explode in an array correctly, I just cant seem to get them all into one array. it would be even more helpful if the first element of the pairs were the array keys. Any guidance would be helpful. Thanks $raw_post_data=file_get_contents("php://input"); $records=explode("\x1e",$raw_post_data,-1); foreach($records as $data){ $pairs=explode("\x1d",$data);}
  3. Thanks PFM, I will try some things with your example. Much obliged...
  4. PFM, I have tried is_array() in about 8 different iterations, on almost all it was always returning true. I am more interested on which element you think I should be checking, this is what seems to be confusing to me. This forum was my latest action, the before actions have taken me two days & reading 100's of examples from tutorials/websites, but I have not seen one example that shows a nested foreach on a non symmetrical array. Do you know of any? Thanks for the reply.
  5. I am a beginner, so forgive me all to whom this is trivial... I have an array, generated from simpleXML object, trying to parse... The array is not symmetrical & I am having trouble finding the right code to make it work. Help & comments are welcomed.. Here is the raw array with print_r: Array ( [Area] => Array ( [0] => Array ( [Name] => Basement [id] => 1 [Room] => Array ( [0] => Array ( [Name] => Equipment [id] => 1 ) [1] => Array ( [Name] => Theater [id] => 9 ) [2] => Array ( [Name] => Wine Cellar [id] => 10 ) ) ) [1] => Array ( [Name] => 1st Floor [id] => 2 [Room] => Array ( [0] => Array ( [Name] => Kitchen [id] => 2 ) [1] => Array ( [Name] => Main Hall [id] => 4 ) [2] => Array ( [Name] => Foyer [id] => 8 ) [3] => Array ( [Name] => Stone Room [id] => 14 ) [4] => Array ( [Name] => Garage Foyer [id] => 16 ) [5] => Array ( [Name] => Dining Room [id] => 17 ) [6] => Array ( [Name] => Living Room [id] => 18 ) [7] => Array ( [Name] => Hearth Room [id] => 19 ) [8] => Array ( [Name] => Office [id] => 20 ) [9] => Array ( [Name] => Powder Room [id] => 21 ) ) ) [2] => Array ( [Name] => 2nd Floor [id] => 3 [Room] => Array ( [0] => Array ( [Name] => Landing [id] => 7 ) [1] => Array ( [Name] => Master Bedroom [id] => 11 ) [2] => Array ( [Name] => Nannys Room [id] => 13 ) [3] => Array ( [Name] => East Kids Bed [id] => 27 ) [4] => Array ( [Name] => West Kids Bed [id] => 28 ) [5] => Array ( [Name] => Kids Bath [id] => 29 ) [6] => Array ( [Name] => Robs Closet [id] => 31 ) [7] => Array ( [Name] => Kelli's Office [id] => 32 ) ) ) [3] => Array ( [Name] => 3rd Floor [id] => 7 [Room] => Array ( [Name] => Bonus room [id] => 5 ) ) [4] => Array ( [Name] => Outside Areas [id] => 8 [Room] => Array ( [0] => Array ( [Name] => Veranda [id] => 22 ) [1] => Array ( [Name] => Back Outdoor [id] => 23 ) [2] => Array ( [Name] => Christmas Lights [id] => 33 ) [3] => Array ( [Name] => Front Outdoor [id] => 34 ) [4] => Array ( [Name] => Garage [id] => 35 ) [5] => Array ( [Name] => Poolhouse Kitchen [id] => 24 ) [6] => Array ( [Name] => Poolhouse Utility [id] => 25 ) ) ) ) ) Here is the code: foreach($xml2['Area'] as $v){ echo $v['Name'],' <br>'; foreach($v['Room'] as $v2){ echo ' ',$v2['Name'],' <br>'; } } Here is the result: Basement Equipment Theater Wine Cellar 1st Floor Kitchen Main Hall Foyer Stone Room Garage Foyer Dining Room Living Room Hearth Room Office Powder Room 2nd Floor Landing Master Bedroom Nannys Room East Kids Bed West Kids Bed Kids Bath Robs Closet Kelli's Office 3rd Floor B 5 Outside Areas Veranda Back Outdoor Christmas Lights Front Outdoor Garage Poolhouse Kitchen Poolhouse Utility The problem lies with the "3rd Floor" which should contain "Bonus Room" as the room. I know that this is the only element that has no "Rooms" array, but I can't figure out how to code the trap for it. With this data, the condition could exist anywhere, not just my example, but I am stumped with the non symmetrical array that I am unfamiliar with. Any help? Thanks. --akaweed
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.