Jump to content

array_search for multi-dimensional array


utherwun

Recommended Posts

First off, first post here.   ;D

 

I came here because the title is aptly named.

 

I'm having a little bit of a difficulty searching a specific array. It is a mixture of other arrays with some being associative and some index-based. It looks similar to below:

 

$stationData['id']['Orders'][0]['ordernum' => value, 'startTime' => moreValue, 'endTime' => finalValue];

$stationData['id']['ProcessingTimes'][0] = array( of single values );

$stationData['id']['AverageProcTime'] = single value;

$stationData['id']['QueueTimes'][0] = array( of single values );

$stationData['id']['AverageQTime'] = single value;

 

There are a total of 8 stations, from '1' -> '8'

In order to derive the queue time I need to see if an ordernum exists in station 1 and 2, and if it does to calculate the difference between startTime of 2 and endTime of 1. Same process goes on with the other stations. Everything works fine and I've verified that the cluster turd I made an array of ($stationData) does accurately store the data I send to it where I want it stored.

 

Whenever I do:

 

foreach ($stationData['1']['Orders'] as $data) {

  $index = array_search($data['orderNumber'], $stationData[2]['Orders']));

}

 

all it does is give me $index as null or a blank value, doesn't return anything at all. I know I could loop through each array of orders and compare individual but I think the computational complexity of that would be silly AND I need the index so I can go directly to the location in that specific array.

 

Any ideas to make this work?  I'm also open to other possible ways of doing this.  :)

 

TIA!

Link to comment
https://forums.phpfreaks.com/topic/42840-array_search-for-multi-dimensional-array/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.