Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Does PHP have an alternative to perl's $_ ? 1

Status
Not open for further replies.

Xaqte

IS-IT--Management
Oct 4, 2002
971
US
I've used perl for some time now. However, over the last six to seven months I've been working with PHP just as much.

I've been able to find many alternatives to my commonly used perl solutions. However, this one has got me stumped.

Does anyone know of a PHP alternative to perls $_ ?

Thanks in advance for any thoughts/experiences!

X

FYI: you can find reference to this in the perl docs:

 
I have a better idea. Instead of having a bunch of PHP people dig through perl documentation, why don't you just tell us what $_ does?



Want the best answers? Ask the best questions! TANSTAAFL!
 
Without getting too detailed...
It is a standard scalar variable that can be use many of ways.

One such use:
Code:
for (@array) {
   print $_;
}


That is the link to the definition... but I understand if you don't want to look... I'm just finding to difficult to explain easily, sorry!

Thanks!

FYI: You need to copy and past the link, I couldn't get it formatted right.
 
I think I can state without fear of contradiction that PHP has nothing like that.

In some cases, there are partial, specifi-use PHP equivalents. See current() when iterating arrays.

Without knowing that it is you're trying to do, it's difficult to advise you.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Hi,

You can do something like this (if this is what you're looking to do):

Code:
<?php

$my_arr = array ("Abc", "Def", "Ghi");

foreach($my_arr as $value)
  echo "$value<br />";

$another_arr = array("Name"=>"John Doe", "Address"=>"126 Main", "ZIP"=>"12345");

foreach($another_arr as $key=>$value)
  echo "$key : $value<br />";

?>

The result would look like this:

Code:
Abc
Def
Ghi
Name : John Doe
Address : 126 Main
ZIP : 12345

Regards


Jakob
 
The answer is no. There are some situations when php has a specific function that will oblige, like the current() function, but as far as the general scope of the $_ perl variable, nothing exists in php.

As far as I know the creator (and later the creators) decided against having things like that as it makes reading the language and overcoming the learning curve much more difficult --even for seasoned programmers.



Robert Carpenter
Remember....eternity is much longer than this ~80 years we will spend roaming this earth.
ô¿ô
 
Thanks guys!

I thought it would be too good to be true.

X
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top