Qaaolchoura Posted August 7, 2009 Share Posted August 7, 2009 Hello, sorry if this is idiotic, but I couldn't find the answer either elsewhere. Is there a way to include a double (or more) arrow in an array, without using subarrays? For example, if I had a set of information about music that I wanted to export as xml (as I did for an experiment). </php <-- create document, header, etc--> $dataArray = array("Graceland" => "Paul Simon" => "Rock", "Days of Future Passed" => "Moody Blues" => "Rock"); foreach($dataArray as $nameArr => $artistArr => $genreArr) { //create data for name $name = $dom->createElement('name'); $nameText = $dom->createTextNode($nameArr); $name->appendChild($nameText); <--repeat for $artist & $genre--> // create node for album and add data as child $album = $dom->createElement('album'); $album->appendChild($name); $album->appendChild($artist); $album->appendChild($genre); } <--output xml--> ?> I get an error because of the unexpected double arrow. Ultimately I'd want to draw this from a mySQL database rather than using static arrays, but I'm still wondering if there's a way to do this. It seems like it'd be useful if I wanted to pass arrays from one php file to another. Thanks, ~Q Link to comment https://forums.phpfreaks.com/topic/169256-solved-double-arrow-in-arrays/ Share on other sites More sharing options...
mikesta707 Posted August 7, 2009 Share Posted August 7, 2009 no there is not. I don't even know what you are trying to accomplish with more than 1 =>. Just use a multi-dimensional array. Link to comment https://forums.phpfreaks.com/topic/169256-solved-double-arrow-in-arrays/#findComment-893131 Share on other sites More sharing options...
wildteen88 Posted August 7, 2009 Share Posted August 7, 2009 I assume by double arrow you mean this foreach($dataArray as $nameArr => $artistArr => $genreArr) No this is not possible. You'll have to use a subarray. Whats wrong with using a sub array? Link to comment https://forums.phpfreaks.com/topic/169256-solved-double-arrow-in-arrays/#findComment-893132 Share on other sites More sharing options...
Qaaolchoura Posted August 7, 2009 Author Share Posted August 7, 2009 It seemed like it'd be easier for me to handle for small datasets than a subarray, but yeah, when I say it I realize that's a bad reason. Any rate, thanks ~Q Link to comment https://forums.phpfreaks.com/topic/169256-solved-double-arrow-in-arrays/#findComment-893142 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.