php_joe Posted April 15, 2008 Share Posted April 15, 2008 I have a list of arrays like this: <? $msg[2008][105][7][45][18][0] = array("7:45:18", "Admin", "public", "Hello."); $msg[2008][105][7][45][19][0] = array("7:45:19", "Admin", "public", "This is a test."); $msg[2008][105][7][45][20][0] = array("7:45:20", "Admin", "public", "This is only a test."); $msg[2008][105][7][45][21][0] = array("7:45:21", "Admin", "public", "If this were a real chat."); $msg[2008][105][7][45][22][0] = array("7:45:22", "Admin", "public", "I wouldn't be talking to myself."); ?> I want to process only the arrays that follow a specified key, such as $msg[2008][105][7][45][20][0]. I wrote this code, but it processes every array, not just the ones following $msg[2008][105][7][45][20][0]. <? $last = "2008.105.7.45.20.0"; // <== the keys are year, day, hour, minute, second, and microsecond $last2 = explode('.', $last); if($msg){ if($msg) foreach($msg as $key_year => $value1){ if($key_year >= $last2[0]) foreach($msg[$key_year] as $key_day => $value2){ if($key_day >= $last2[1]) foreach($msg[$key_year][$key_day] as $key_hour => $value3){ if($key_hour >= $last2[2]) foreach($msg[$key_year][$key_day][$key_hour] as $key_min => $value4){ if($key_min >= $last2[3]) foreach($msg[$key_year][$key_day][$key_hour][$key_min] as $key_sec => $value5){ foreach($msg[$key_year][$key_day][$key_hour][$key_min][$key_sec] as $key_micro => $piece){ if($key_sec > $last2[4]) $text .= display_text($piece); if($key_sec = $last2[4] && $key_micro >= $last2[5]) $text .= display_text($piece); } } } } } } } ?> What have I done wrong? Quote Link to comment Share on other sites More sharing options...
Barand Posted April 15, 2008 Share Posted April 15, 2008 Why not just store as <?php $msg['2008.105.7.45.18.0'] = array("7:45:18", "Admin", "public", "Hello."); $msg['2008.105.7.45.19.0'] = array("7:45:19", "Admin", "public", "This is a test."); $msg['2008.105.7.45.20.0'] = array("7:45:20", "Admin", "public", "This is only a test."); $msg['2008.105.7.45.21.0'] = array("7:45:21", "Admin", "public", "If this were a real chat."); $msg['2008.105.7.45.22.0'] = array("7:45:22", "Admin", "public", "I wouldn't be talking to myself."); ?> Quote Link to comment Share on other sites More sharing options...
php_joe Posted April 16, 2008 Author Share Posted April 16, 2008 Why not just store as <?php $msg['2008.105.7.45.18.0'] = array("7:45:18", "Admin", "public", "Hello."); $msg['2008.105.7.45.19.0'] = array("7:45:19", "Admin", "public", "This is a test."); $msg['2008.105.7.45.20.0'] = array("7:45:20", "Admin", "public", "This is only a test."); $msg['2008.105.7.45.21.0'] = array("7:45:21", "Admin", "public", "If this were a real chat."); $msg['2008.105.7.45.22.0'] = array("7:45:22", "Admin", "public", "I wouldn't be talking to myself."); ?> I thought that keys couldn't be longer than 10 digits. I seem to remember trying a single key at first, but getting errors. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.