Finding indexes of elements in nested arrays

I have an array arr = [[[1, 2], [3, 4]], [5, 6]]. I am looking for a function f that returns me the indexes of the elements also in the nested array given only arr as input. For example, function(arr, 2) -> (0, 0, 1) Has some library implemented it? Of course it’s not a… Read More Finding indexes of elements in nested arrays

How do I combine inner arrays of a 2D array based on first identical value?

foreach ($files as $file) { $filename = substr($file, 0, strrpos($file, ‘.’)) . ‘.jpg’; // file name with .jpg extension // lots of irrelevant code between here if (isset($filename)) { $newProcessedFileNames[] = $filename; } } $testArray = []; $result = array_values($newProcessedFileNames); foreach ($result as $row) { $string = explode(‘\\’, $row); $testArray[] = $string; } prettyPrint($testArray); //… Read More How do I combine inner arrays of a 2D array based on first identical value?

Quick way of checking if a 2D array contains an element c#

I’m currently coding battleships as a part of a college project. The game works perfectly fine but I’d like to implement a way to check if a ship has been completely sunk. This is the method I’m currently using: public static bool CheckShipSunk(string[,] board, string ship){ for(int i = 0; i < board.GetLength(0); i++){ for(int… Read More Quick way of checking if a 2D array contains an element c#

php multidimensional array sorting using inner value

I have the following array: Array ( [ret_code] => 0 [ret_msg] => OK [result] => Array ( [0] => Array ( [symbol] => 10000NFTUSDT [bid_price] => 0.004085 [ask_price] => 0.004095 [last_price] => 0.004085 [last_tick_direction] => MinusTick [prev_price_24h] => 0.004090 [price_24h_pcnt] => -0.001222 [high_price_24h] => 0.004120 [low_price_24h] => 0.004040 ) [1] => Array ( [symbol] =>… Read More php multidimensional array sorting using inner value