How to create a string from one row of a two-dimensional character array in PHP

1 Answer

0 votes
// Create and initialize the 2D array
$charArray2D = array(
    array('P', 'H', 'P'),
    array('s', 'c', 'r', 'i', 'p', 't', 'i', 'n', 'g' ),
    array('l', 'a', 'n', 'g', 'u', 'a', 'g', 'e' )
);

// row 1 (second row)
$row_index = 1;
$selected_row = $charArray2D[$row_index];

// Convert the row to a string
$s = implode('', $selected_row);

echo $s;  


   
/*
run:
    
scripting
    
*/

 



answered Feb 7, 2025 by avibootz
...