Something like "WHERE" from SQL

Is there a way to accomplish something like the "WHERE" syntax from SQL
in php? For example an equivalent to the following, which I know is
not proper php syntax.

foreach ($var as $key => $value WHERE $key != '3') {
echo "$key is $value";
}

or

implode (",", $_POST WHERE $_POST[name] != 'post');

I keep wanting to be able to do things like this.

--Kenoli
kenoli [ Do, 23 November 2006 15:41 ] [ ID #1545691 ]

Re: Something like "WHERE" from SQL

Kenoli wrote:
> Is there a way to accomplish something like the "WHERE" syntax from SQL
> in php? For example an equivalent to the following, which I know is
> not proper php syntax.
>
> foreach ($var as $key => $value WHERE $key != '3') {
> echo "$key is $value";
> }
>
> or
>
> implode (",", $_POST WHERE $_POST[name] != 'post');
>
> I keep wanting to be able to do things like this.
>
> --Kenoli

foreach ($var as $key => $value) {
if $key != '3'
echo "$key is $value";
Captain Paralytic [ Do, 23 November 2006 15:48 ] [ ID #1545692 ]

Re: Something like "WHERE" from SQL

Kenoli wrote:
> Is there a way to accomplish something like the "WHERE" syntax from
> SQL in php? For example an equivalent to the following, which I know
> is not proper php syntax.
>
> foreach ($var as $key => $value WHERE $key != '3') {
> echo "$key is $value";
> }
>
> or
>
> implode (",", $_POST WHERE $_POST[name] != 'post');
>
> I keep wanting to be able to do things like this.


array_filter();
http://nl3.php.net/manual/en/function.array-filter.php

The problem here is you cannot filter on keys.

On could use array_keys(), array_filter() and then again array_flip() and
array_intersect_keys(). It's hardly better then a foreach loop however, and
a lot less readable.
--
Rik Wasmus
Rik [ Mo, 27 November 2006 17:47 ] [ ID #1548801 ]
PHP » alt.php.sql » Something like "WHERE" from SQL

Vorheriges Thema: Connect with Access ?
Nächstes Thema: I need some help here