![]() |
Finding Value in Array using isset - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Finding Value in Array using isset (/showthread.php?tid=24352) Pages:
1
2
|
Finding Value in Array using isset - El Forum - 11-07-2009 [eluser]Fielder[/eluser] I'm having a problem getting this isset command to locate a particular value in my array. It keeps going into the IF statement. Am I missing something? I'm getting "Undefined index: 2975" error, when I know for a fact 2975 exists in the storeArray $key and $row['store_id']. I've var_dump both $storeArray and $stores and they both show 2975. Any ideas? Let me know if more info. is needed. Code: foreach ($c as $key => $val) var_dump for $storeArray Code: array(8) { [2975]=> array(11) { ["storename"]=> string(9) "Appletree" ["storenum"]=> string(3) "736" ["newAd_count"]=> int(4) ["renewAd_count"]=> int(4) ["totAd_count"]=> int(8) ["spaces_count"]=> int(10) ["print"]=> string(1) "Y" ["lastqtrAd_count"]=> int(9) ["cancelled"]=> int(1) ["freeAd_count"]=> int(4) ["revenue"]=> string( var_dump for $stores Code: [287]=> array(14) { ["store_id"]=> string(4) "2975" ["storename_name"]=> string(9) "Appletree" ["store_number"]=> string(3) "736" ["store_address"]=> string(11) "2000 Hwy 21" ["store_city"]=> string(5) "Bryan" ["store_state"]=> string(2) "TX" ["store_zip"]=> string(5) "77803" ["store_cycle"]=> string(1) "B" ["store_phone"]=> string(14) "(979) 778-0134" ["store_notes"]=> string(0) "" ["store_open"]=> string(1) "1" ["store_alive"]=> string(1) "1" ["store_upscode"]=> string(11) "APT001-0736" ["zone_number"]=> string(1) "1" } Finding Value in Array using isset - El Forum - 11-07-2009 [eluser]skunkbad[/eluser] What happens if you var_dump($storeArray[$row['store_id']]) right before the if statement ?? Finding Value in Array using isset - El Forum - 11-07-2009 [eluser]Fielder[/eluser] NULL Finding Value in Array using isset - El Forum - 11-07-2009 [eluser]Fielder[/eluser] I think it has something to do with the datatype of the keys. Within my code, I'm merging a 2nd array($subTotal) with my primary $storeArray. $storeArray keys are all numeric, ie 2975. However, the keys on $subTotal are alpha, ie Appletree. So now my $storeArray has mixed key datatypes between numeric and alpha. Could that be causing a problem with my isset? Code: $subTotal = $this->rtui_app->subTotal($storeArray); Finding Value in Array using isset - El Forum - 11-07-2009 [eluser]mah0001[/eluser] On which line you are getting the Undefined index error? Finding Value in Array using isset - El Forum - 11-07-2009 [eluser]Fielder[/eluser] I'm sorry, let me clarify. It always goes into the IF statement as per my code in the original post because of the !, and does not throw an error. I only get the Undefined index error when I throw in var_dump($storeArray[$row['store_id']]) anywhere. Quote:A PHP Error was encountered Finding Value in Array using isset - El Forum - 11-07-2009 [eluser]Fielder[/eluser] I get these also 'Appletree' key comes from the merged array with $storeArray. Code: var_dump($storeArray['Appletree']); Quote:array(11) { ["storename"]=> string(9) "Appletree" ["storenum"]=> string(5) "Total" ["newAd_count"]=> int(2) ["renewAd_count"]=> int(7) ["totAd_count"]=> int(9) ["spaces_count"]=> int(10) ["print"]=> int(0) ["lastqtrAd_count"]=> int(8) ["cancelled"]=> int(1) ["freeAd_count"]=> int(2) ["revenue"]=> string(8) "$ 345.04" } and this actually gives me Undefined Offset on the var_dump, but still spits out the dump below. Code: var_dump($storeArray[2975]); Quote:array(11) { ["storename"]=> string(9) "Appletree" ["storenum"]=> string(3) "736" ["newAd_count"]=> string(1) "0" ["renewAd_count"]=> string(1) "0" ["totAd_count"]=> string(1) "0" ["spaces_count"]=> string(1) "0" ["print"]=> string(1) "N" ["lastqtrAd_count"]=> string(1) "0" ["cancelled"]=> string(1) "0" ["freeAd_count"]=> string(1) "0" ["revenue"]=> string(6) "$ 0.00" } and this gives me Undefined index on the var_dump as previously mentioned. Still spits out the dump below. Code: var_dump($storeArray['2975']); Quote:array(11) { ["storename"]=> string(9) "Appletree" ["storenum"]=> string(3) "736" ["newAd_count"]=> string(1) "0" ["renewAd_count"]=> string(1) "0" ["totAd_count"]=> string(1) "0" ["spaces_count"]=> string(1) "0" ["print"]=> string(1) "N" ["lastqtrAd_count"]=> string(1) "0" ["cancelled"]=> string(1) "0" ["freeAd_count"]=> string(1) "0" ["revenue"]=> string(6) "$ 0.00" } Finding Value in Array using isset - El Forum - 11-07-2009 [eluser]mah0001[/eluser] replace your var_dump($storeArray[2975]) with the code below, and re-post the output. Code: echo 'start'; If you get a Undefined index or Offset notice, you should not be getting any other output from the var_dump. Finding Value in Array using isset - El Forum - 11-08-2009 [eluser]Fielder[/eluser] Code: echo 'start'; output with no var_dump results. Quote:start When I move the var_dump inside the foreach... Code: foreach ($stores as $row) Output. Note that the foreach loops through all $stores instances. It seems when it reaches 2975 it starts output the var_dump. Quote:. Finding Value in Array using isset - El Forum - 11-08-2009 [eluser]mah0001[/eluser] It looks like the key 2975 exists, Change your code to: Code: foreach ($stores as $row) You should see the values for the 2975 key printed instead of NULL. I think your problem is starting after you merge your array: Code: $subTotal = $this->rtui_app->subTotal($storeArray); Add the var_dump after the merge and post the part where you see your key 2975. Code: $subTotal = $this->rtui_app->subTotal($storeArray); |