3v4l.org

run code in 300+ PHP versions simultaneously
<?php $stock = ["7", "5", "3"]; $request = ["3", "6", "3"]; echo "Are there any items with insufficient stock: "; var_export( array_any( $stock, fn($v, $i) => $v < $request[$i] ) ); echo "\n---\nDo all items have sufficient stock: "; var_export( array_all( $stock, fn($v, $i) => $v >= $request[$i] ) ); echo "\n---\nWhich stock item value is insufficient: "; // more helpful if $v was a row from a 2d array var_export( array_find( $stock, fn($v, $i) => $v < $request[$i] ) ); echo "\n---\nWhich stock indexes have an insufficient amount: "; var_export( array_find_key( $stock, fn($v, $i) => $v < $request[$i] ) );
Output for 8.4.1 - 8.4.14
Are there any items with insufficient stock: true --- Do all items have sufficient stock: false --- Which stock item value is insufficient: '5' --- Which stock indexes have an insufficient amount: 1
Output for 8.1.32, 8.2.0 - 8.2.29, 8.3.0 - 8.3.27
Are there any items with insufficient stock: Fatal error: Uncaught Error: Call to undefined function array_any() in /in/DBpAE:8 Stack trace: #0 {main} thrown in /in/DBpAE on line 8
Process exited with code 255.

preferences:
69.41 ms | 407 KiB | 5 Q