Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

if statement thingy

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

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?
bonkers
New php-forum User
New php-forum User
 
Posts: 46
Joined: Wed Mar 12, 2003 7:17 pm

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.
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

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?
bonkers
New php-forum User
New php-forum User
 
Posts: 46
Joined: Wed Mar 12, 2003 7:17 pm

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
User avatar
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

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

like this:
Code: Select all

if($variable == $variable->functionThatReturnsArray())
{
     [i]stuff[/i]   
}
bonkers
New php-forum User
New php-forum User
 
Posts: 46
Joined: Wed Mar 12, 2003 7:17 pm

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
WiZARD
Moderator
Moderator
 
Posts: 1257
Joined: Thu Jun 20, 2002 10:14 pm
Location: Ukraine, Crimea, Simferopol

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.
pootergeist
New php-forum User
New php-forum User
 
Posts: 191
Joined: Wed Jan 29, 2003 7:11 am
Location: UK


Return to PHP coding => General

Who is online

Users browsing this forum: TurnitinBot [Bot] and 4 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.