physaux Posted October 15, 2009 Share Posted October 15, 2009 Ok guys, so i have got this following dilemma: I have an Array declared, and used all without problems, here it is: $Data[$index][$index2]["Name"] The "Name" index works fine because i have declared it for each $index and $index2. The problem comes up as so: I want to have another index, called "Links". So the finished product could be accessed like so: $Data[$index][$index2]["Links"][1] = "sometext"; $Data[$index][$index2]["Links"][2] = "moretext"; $Data[$index][$index2]["Links"][3] = "ahilovewriting..."; The problem is that i make the above declarations throughout my code. So i take it i need to have ["Links"][1] to be ready to accept information. So i decided to add the following line to my code when i look through all the indexes: $Data[$index][$index2]["Links"]; But i got the following error: Undefined index: Links in /Users/../ on that line so my question is, how can i "prepare" (or do i need to) my array ["Links"] so that i can do the following operations to it: count(Data[$index][$index2]["Links"]) //GAVE ME AN ERROR BEFORE, i thought it would give me 0. isset(Data[$index][$index2]["Links"]) //IDK even what happened here, this is later on and i didn't get to it yet without errors. So how can i make this work? Thanks for your help!!! Link to comment https://forums.phpfreaks.com/topic/177818-solved-problem-undefined-index-how-can-i-declare-an-index-without-putting-in-info/ Share on other sites More sharing options...
mikesta707 Posted October 15, 2009 Share Posted October 15, 2009 try $Data[$index][$index2]["Links"] = array(); Link to comment https://forums.phpfreaks.com/topic/177818-solved-problem-undefined-index-how-can-i-declare-an-index-without-putting-in-info/#findComment-937610 Share on other sites More sharing options...
simshaun Posted October 15, 2009 Share Posted October 15, 2009 What you posted is a little bit confusing (to me anyway). It may be easier to help you if you post the full code. I came up with a short little example that may (or may not) help you: <?php ini_set('display_errors', 1); error_reporting(E_ALL); $vehicles = array(); $vehicles['Ford'][] = 'F250'; $vehicles['Ford'][] = 'F350'; echo "<pre>"; print_r($vehicles['Ford']); echo "</pre>"; // No errors up to this point because 'Ford' exists. // Throws an undefined index error because 'Chevy' is not yet defined. echo "<pre>"; print_r($vehicles['Chevy']); echo "</pre>"; // Make sure the index exists before doing anything if (isset($vehicles['Toyota'])) { echo "<pre>"; print_r($vehicles['Toyota']); echo "</pre>"; // No error } echo "<pre>"; print_r($vehicles['Toyota']); echo "</pre>"; // Throws an undefined index error because 'Toyota' is not yet defined. Link to comment https://forums.phpfreaks.com/topic/177818-solved-problem-undefined-index-how-can-i-declare-an-index-without-putting-in-info/#findComment-937615 Share on other sites More sharing options...
physaux Posted October 15, 2009 Author Share Posted October 15, 2009 Thank you, that really helped me with it! Link to comment https://forums.phpfreaks.com/topic/177818-solved-problem-undefined-index-how-can-i-declare-an-index-without-putting-in-info/#findComment-937618 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.