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



Shannon,

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.


In PHP, arrays do not have to use numeric indexes; instead the arrays are
"associative" and you can use strings (or numbers) as an array index. This
is actually very powerful, and something I learned to love in AWK back in
the early 90's. Anyway, you don't "add a new element to that array *at that
index*" (emphasis mine). You can add an element, change the value of an
element, or remove an element at will.

Using your variable names, to update the value of the index located:

$theArrayToSearch[ $found ] = "new value";

To add a new element with some new index:

$theArrayToSearch[ 'some new index' ] = "some value";

To remove an element from an array:

unset( $theArrayToSearch[ $found ] );

Within the square brackets can be a variable name, constant, or expression,
but the resulting value will be the array index. It does not have to be a
number; it can be a string.

Multi-dimension arrays just need multiple sets of square brackets, like
$array[ $dim1 ][ $dim2 ][ $dim3 ] = value;

As an Amazon Associate we earn from qualifying purchases.

This thread ...

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.