r/PHPhelp • u/GuybrushThreepywood • Sep 05 '26
Will the upcoming Partial Function Application improve this code?
I'm wondering how these lines of code could change:
$placeholders = $idsArray
|> count( ... )
|> ( fn ( $x ) => array_fill( 0, $x, '?' ) )
|> ( fn ( $x ) => implode( ',', $x ) );I don't like how the above is written, therefore I currently stick to using:
$placeholders = str_repeat('?,', count( $idsArray ) - 1) . '?';or
$placeholders = implode( ',', array_fill( 0, count( $idsArray), '?' ) );
2
Upvotes
View all comments
Show parent comment
5
u/obstreperous_troll Sep 05 '26
The placeholder syntax is
?for a single arg, so it'd beI imagine
count(?)would work too. But TBH, while I'm a fan of pipelines and composition in general, I'd probably just go with the str_repeat version for this particular case.