if statement thingy

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

bonkers
New php-forum User
New php-forum User
Posts: 46
Joined: Wed Mar 12, 2003 7:17 pm

if statement thingy

Postby bonkers » Fri Jun 13, 2003 11:43 pm

in C++ I can do this:

if($joe == getArray()[4])

it will compare $joe and the 5th ([4]) element of the returned array from the varialb getArray(). How can I do this in PHP?

User avatar
WiZARD
Moderator
Moderator
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Re: if statement thingy

Postby WiZARD » Sat Jun 14, 2003 12:30 am

bonkers wrote:in C++ I can do this:

if($joe == getArray()[4])

it will compare $joe and the 5th ([4]) element of the returned array from the varialb getArray(). How can I do this in PHP?

in PHP similar:

Code: Select all

if($joe == $var_arr[4])

where $var_arr is array.

bonkers
New php-forum User
New php-forum User
Posts: 46
Joined: Wed Mar 12, 2003 7:17 pm

Postby bonkers » Sat Jun 14, 2003 10:41 am

Wait but that means I can't call the function in the if statement that returns the array?

User avatar
WiZARD
Moderator
Moderator
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Postby WiZARD » Sun Jun 15, 2003 3:19 am

bonkers wrote:Wait but that means I can't call the function in the if statement that returns the array?

for what? array it's like veriable! for whot need it call than you may just point to variable-array

bonkers
New php-forum User
New php-forum User
Posts: 46
Joined: Wed Mar 12, 2003 7:17 pm

Postby bonkers » Sun Jun 15, 2003 7:12 am

like this:

Code: Select all


if($variable == $variable->functionThatReturnsArray())
{
     [i]stuff[/i]   
}

User avatar
WiZARD
Moderator
Moderator
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol
Contact:

Postby WiZARD » Mon Jun 16, 2003 12:07 am

bonkers wrote:like this:

Code: Select all


if($variable == $variable->functionThatReturnsArray())
{
     [i]stuff[/i]   
}

just translate to PHP

Code: Select all

if (is_array($variable))
{   stuff   };

User avatar
pootergeist
New php-forum User
New php-forum User
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK
Contact:

Postby pootergeist » Mon Jun 16, 2003 5:44 am

I think you may need to pass the index to the function and have the function return the array value for that index

$joe = 'b';
$my_array = array('a','b');
function &ret_index($array_name,$indx)
{
return $array_name[$indx];
}

if($joe =& ret_index($my_array,2))
{
echo 'yup';
}

very untested though.
I don't think PHP naturally has returned values from functions, you'd have to code your own workaround.


Return to “PHP coding => General”

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron