× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Glenn...isn't that the truth. I've learned more from the comments than from
the manual portion.

On Wed, Jul 7, 2010 at 1:47 PM, Glenn Hopwood <ghopwood.list@xxxxxxxxx>wrote:

There's lots of code for multi-dimensional array searches at the bottom
of the php.net page that Tom sent. (I love the comments portion of php.net
)

http://www.php.net/manual/en/function.array-search.php

Glenn

On 7/7/2010 12:58 PM, Shannon ODonnell wrote:
That's interesting! That works really well for a single level array.

But...if I had a multidimensional array, how would I use array_search to
find a match?

Assume the following MDA:

$Array1[0] = array("key1"=>"apple",
"key2"=>"pear",
"key3"=>"fruit");

$Array1[1] = array("key1"=>"Carrot",
"key2"=>"Potato",
"key3"=>"vegetable");


Let's say I wanted to do something like find the array index (key) for
Potato.

$foundindex = array_search("potato", $Array1);

This doesn't work by the way, but that's my question...what would be the
syntax to find Potato?

Thanks!


-----Original Message-----
From: pctech-bounces@xxxxxxxxxxxx [mailto:pctech-bounces@xxxxxxxxxxxx]
On Behalf Of Tom Jedrzejewicz
Sent: Wednesday, July 07, 2010 10:54 AM
To: PC Technical Discussion for iSeries Users
Subject: Re: [PCTECH] Add/Update an Array Element PHP

Use array_search, which returns the value of the first match ...

http://www.php.net/manual/en/function.array-search.php
http://forums.zend.com/viewtopic.php?f=63&t=1407

---------
Tom Jedrzejewicz
tomjedrz@xxxxxxxxxxxxxx



On Wed, Jul 7, 2010 at 8:18 AM, Shannon ODonnell
<sodonnell@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
So this is driving me crazy trying to figure out the syntax.



Very probably I'm overthinking it and making it harder than it needs to
be
but.



In RPG, it's really easy to find an element in an array based on some
value,
and then to update that array element at the found index.



If myArray(idx) = "T"

Eval myArray(idx) = "F";

Endif;





But how do I do that in PHP?



I can search for a value in an array using in_array:



$found = in_array($myValueToSearchFor, $theArrayToSearch)

If($found)

{

}





But I can't quite figure out, once I know that my value is in that
array, of
how to update that particular array element and/or add a new element to
that array at that index.







Shannon O'Donnell





--
This is the PC Technical Discussion for iSeries Users (PcTech) mailing
list
To post a message email: PcTech@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/pctech
or email: PcTech-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/pctech.


--
This is the PC Technical Discussion for iSeries Users (PcTech) mailing list
To post a message email: PcTech@xxxxxxxxxxxx
To subscribe, unsubscribe, or change list options,
visit: http://lists.midrange.com/mailman/listinfo/pctech
or email: PcTech-request@xxxxxxxxxxxx
Before posting, please take a moment to review the archives
at http://archive.midrange.com/pctech.


As an Amazon Associate we earn from qualifying purchases.

This thread ...

Follow-Ups:
Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.