Jump to content

gordon142

New Members
  • Posts

    6
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

gordon142's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I believe I've figured it out. Never could get stuff to properly append at the third level, but I can achieve the same final product by creating the arrays separating, the stacking them one at a time, like so: <?php $levelone = array(); $leveltwo = array(array( 'name' => $stop_location, 'time1' => $next_arrival, 'direction1' => $bus_direction, 'time2' => $second_arrival, 'direction2' => $bus_return, 'weekendservice' => $weekend_service )); $leveltwo[] = array( 'name' => $stop_location, 'time1' => $next_arrival, 'direction1' => $bus_direction, 'time2' => $second_arrival, 'direction2' => $bus_return, 'weekendservice' => $weekend_service ); ##print_r($leveltwo); $levelone['Departure Locations'] = $leveltwo; print_r($levelone); ?> Which outputs: Array ( [Departure Locations] => Array ( [0] => Array ( [name] => [time1] => [direction1] => [time2] => [direction2] => [weekendservice] => ) [1] => Array ( [name] => [time1] => [direction1] => [time2] => [direction2] => [weekendservice] => ) ) ) Which is what I want. Cool.
  2. Unfortunately, in this instance that produces output completely identical to the output of $final_output[0][0].
  3. Still not getting it to work. Here is the code I'm running (the variable values stripped from the script, as they add nothing to this example): <?php $final_output = array( 'Departure Locations' => Array ( '0' => Array ( 'name' => $stop_location, 'time1' => $next_arrival, 'direction1' => $bus_direction, 'time2' => $second_arrival, 'direction2' => $bus_return, 'weekendservice' => $weekend_service ) ) ); $final_output[0][0] = array( 'name' => $stop_location, 'time1' => $next_arrival, 'direction1' => $bus_direction, 'time2' => $second_arrival, ' direction2' => $bus_return, 'weekendservice' => $weekend_service ); print_r($final_output); ?> Here is what it returns: Array ( [Departure Locations] => Array ( [0] => Array ( [name] => Templeton [time1] 6: 00 PM => [direction1] => null [time2] 7: 04 PM => [direction2] => null [weekendservice] => true ) ) [0] => Array ( [0] => Array ( [name] => Law School [time1] => 5: 43 PM [direction1] => To Lewis and Clark [time2] => 6: 05 PM [ direction2] => To Pioneer Square [weekendservice] => true ) ) ) Here is what it SHOULD return: Array ( [Departure Locations] => Array ( [0] => Array ( [name] => Templeton [time1] => 6: 00 PM [direction1] => null [time2] => 7: 04 PM [direction2] => null [weekendservice] => true ) [1] => Array ( [name] => Law School [time1] => 5: 43 PM [direction1] => To Lewis and Clark [time2] => 6: 05 PM [direction2] => To Pioneer Square [weekendservice] => true ) ) )
  4. OK, that is almost perfect, except that that code you posted seems to create a NEW array on the second level, then another array within that one. Reading back I did not actually make this clear in my initial posting, but what I want to do is to create a new third-level array within an existing second-level array: existing_array > existing_array > existing_array new_array_here The above tree is now an exact representation of my arrays and what I want to do with them. You might ask why I would need a third-level array at all if I have only a single second-level array. The reason is that after the array structure is properly created, the entire thing is going to be run through json_encode. For the json to parse properly for my uses, I need the three levels of arrays. Many thanks.
  5. I'm sure there must be a simple solution, but I've scoured the net and come up blank. I have a three-dimensional array. I want to append a new array to the third level. In other words, it would be: array > array > array array array new_array_here If I simply do: $3darray = array('value1'); it appends it as a new array on the second level of 3darray, but I can't find any way to append it further down than that…
  6. I have a number of numerical values in an array. I want to take another value and search the array for the first value in the array that is larger than the other value (the one not in the array). I've tried various methods with in_array but can never get it to do anything except return a parsing error. Help would be appreciated.
×
×
  • 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.