Good Morning All, and HAPPY NEW YEAR to everyone, whether you celebrate it or not...

I have what should be a relatively simple question that I would like to pose that could avoid a very lengthy one...

if I create an associative array and place several key>value pairs in the array, will they remain in the order that they are placed, or will they be re-ordered in any way?

I want to create the array and then run an array_search on the $values to find the minimum value in the array.

I guess that would make a second question... I know I can do an array search on an array that I push values onto, but that isn't an associative array, so not sure I can even do that..

Any feedback would be greatly appreciated and would most likely save me hours of research time.

thanks
Douglas

Happy New Year you too.

First part of question you can make answered with just output of array:

$myArray = array('zero' => '0', 'first' => '1st', 'second' => '2nd', 'third' => '3rd');
print_r($myArray);

Second part of question you can solve with function min but also depends of type of variables you have in values of array.

Hello Douglas and a happy new year,

if I create an associative array and place several key>value pairs in the array, will they remain in the order that they are placed, or will they be re-ordered in any way?

They will remain in the order that you inserted them to the array , except if you want to re-ordered the associative array in any way through various PHP function (e.g. ksort asort)

I know I can do an array search on an array that I push values onto, but that isn't an associative array, so not sure I can even do that..

The same way … array_search will give the index of the array or false if not any matching your criteria.

Thank you Both for your responses...

jkon, I appreciate precise answers, and I believe that your answers were exactly what I was looking for...

I should know how it works for me in the morning and will post the results before marking this as solved...

Thanks again
Douglas

Thanks again jkon.

that was exactly what I needed to solve the problem.

working fine

Douglas

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.