451 questions
2 votes
2 answers
79 views
array_map and filter_var return unexpected results
I have the following code when submitting a form $data['item_cost'] = ( isset( $_POST['item-cost'] ) ? array_map( "filter_var", array_filter( $_POST['item-cost'] ), array( ...
1 vote
1 answer
137 views
Simple Tic-Tac-Toe ReactJS, Generating Component Messing the State
tic-tac-toe game: X | O | O | X | X | O | X I try to learn ReactJS. I already follow tutorial from https://react.dev/learn/tutorial-tic-tac-toe. But had a hard time to solve the 2nd Challenge of ...
0 votes
0 answers
41 views
Optimised Javascript/TS code to find the total quantity for each base item, when more than 1 cart item can be pointing to the same base item
I need the most efficient way to calculate the total quantity for each base item by going through a list of cart items and sum up the quantities for all cart items having the same base item. My ...
1 vote
4 answers
113 views
Use flat array's values to generate an associative array whose keys and values are given a static prefix
Is there a shorthand for the following code: $result = array_combine( array_map(fn($elem) => "key_$elem", $array), array_map(fn($elem) => "value_$elem", $array) ); ...
-1 votes
2 answers
76 views
Storing data from an endpoint to a variable and preventing the variable from accepting data from the endpoint after initial reload
So I have a data response that looks like this - "data": [ { "_id": "65a52c333972416e3ef579a9", "kitchenName": "Micdamilare ...
0 votes
3 answers
524 views
usestate variable increments when I click on a different increment button
so I am declaring a usestate variable as "count" and I am mapping through a list of 2 items. This code shows the variable declaration and the function to increment and decrement const [count,...
0 votes
2 answers
84 views
Create a new array of multiple objects and array from a given array
I have the following array const CARS = [ {make: "skoda", model: "kodiaq", color: "light-blue", id: "1002", category: "A"}, {make: "skoda&...
0 votes
3 answers
101 views
PHP - Is it possible to test the array_map('unlink', glob('/folder/my_files--*.txt')) command by try/catch?
I would like to test if the function array_map('unlink', glob('...*.txt')) did not encounter an error: ex.: try { array_map('unlink', glob('/folder/my_files--*.txt')); } catch (\Exception $e) { ...