Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
There Will Be Penalty
May 18, 2002

Makes a great pet!

duz posted:

Naw, can't do that in PHP. Javascript can do what you want, don't know off hand what else could.

Perl does this.

code:
sub foo {
        return ("zero", "one", "two", "three", "four");
}
print((foo())[2]);
print("\n");
If your function returns a list reference:

code:
sub bar {
        return ["cero", "uno", "dos", "tres", "cuatro"];
}
print(bar()->[2]);
print("\n");
I can't speak for Python or Ruby.

Adbot
ADBOT LOVES YOU

There Will Be Penalty
May 18, 2002

Makes a great pet!

Heskie posted:

My CTO has this exact opinion, and while I don't disagree, Twig/Blade at least make things like escaping sensible. Built in support for things like partials/extending layouts is also nice. I'm also a fan of syntax like foreachelse and unless.

As with anything, you can do it yourself but why bother? PHP League's Plates is a good middle ground I guess.

I've used this 40-line template engine for a few things. It's *bare* minimalism but gets some jobs done. Plates adds some functionality but works pretty much the exact same way.

Did I mention it's only 40 lines of code?

There Will Be Penalty
May 18, 2002

Makes a great pet!
The thing about prepared statements is you can do this:

PHP code:
$sql = "INSERT INTO Owners(Names) VALUES(:item);";
$query = $odb->prepare($sql);
foreach ($items as $item) {
    $results = $query->execute([":item" => $item]);
    /* ... */
}
It's kind of one of the purposes of prepared statements, really.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply