0

In some way, I managed to write code to generate the output array but still I can't solve the center part.Pls,Help me solve it

Input is an matrix of (10x10)The output I need is 8 16 24 32 40 48 56 64 7 10 11 12 13 14 15 63 6 18 19 20 21 22 23 62 5 26 27 36 28 30 31 61 4 34 35 37 29 38 39 60 3 42 43 44 45 46 47 59 2 50 51 52 53 54 55 58 1 9 17 25 33 41 49 57 and my code is here <body><pre><?php $size = 10; $values = []; for ($i = 1; $i <= $size; $i++) { $inputArrayValueow = []; for ($j = 1; $j <= $size; $j++) { $inputArrayValueow[] = $i * $j; } $values[] = $inputArrayValueow; } foreach ($values as $inputArrayValueow) { echo implode("__", $inputArrayValueow) . "\n"; } echo "\n\n\n"; $inputArrayValue = 10; $leftColumnValue = $inputArrayValue - 1; $bottomRowValue1 = $inputArrayValue; $bottomRowValue2 = $inputArrayValue; $innerCellValue = $inputArrayValue + 2; // Top Row for ($j = 1; $j <= $size; $j++) { $topRowValue = $inputArrayValue * $j; echo $topRowValue . "__"; } echo "\n"; // Middle Rows for ($i = 1; $i < $size - 1; $i++) { echo $leftColumnValue . "__"; // Left Column $leftColumnValue--; for ($j = 1; $j < $size - 1; $j++) { echo $innerCellValue . "__"; // Inner Cells $innerCellValue = $innerCellValue + 1; } $innerCellValue += 2; echo ($topRowValue - 1) . "__"; // Right Column $topRowValue--; echo "\n"; } // Bottom Row $bottomRowValue1 = $inputArrayValue - ($inputArrayValue - 1); for ($j = 0; $j < $size; $j++) { echo $bottomRowValue1 . "__"; $bottomRowValue1 = $bottomRowValue1 + $bottomRowValue2; } ?></pre></body> and my output is 10__20__30__40__50__60__70__80__90__100__ 9__12__13__14__15__16__17__18__19__99__ 8__22__23__24__25__26__27__28__29__98__ 7__32__33__34__35__36__37__38__39__97__ 6__42__43__44__45__46__47__48__49__96__ 5__52__53__54__55__56__57__58__59__95__ 4__62__63__64__65__66__67__68__69__94__ 3__72__73__74__75__76__77__78__79__93__ here comes other 2 rows

26th Oct 2023, 4:09 PM
Harshavardhan C
Harshavardhan C - avatar
1 Odpowiedź
0
<?php $size = 10; $values = []; // Generate the initial matrix for ($i = 1; $i <= $size; $i++) { $row = []; for ($j = 1; $j <= $size; $j++) { $row[] = $i * $j; } $values[] = $row; } // Display the initial matrix foreach ($values as $row) { echo implode("__", $row) . "\n"; } echo "\n\n\n"; // Generate and display the additional rows $inputValue = $size; $leftColumnValue = $inputValue - 1; $bottomRowValue1 = $inputValue; // Top Row for ($j = 1; $j <= $size; $j++) { echo ($inputValue * $j) . "__"; } echo "\n"; // Middle Rows for ($i = 1; $i < $size - 1; $i++) { echo $leftColumnValue . "__"; // Left Column $leftColumnValue--; for ($j = 1; $j < $size - 1; $j++) { echo $inputValue + 2 . "__"; // Inner Cells $inputValue += 2; } echo ($inputValue - 1) . "__"; // Right Column $inputValue--; echo "\n"; }
27th Nov 2023, 11:29 PM
Abdulfattah Alhazmi
Abdulfattah Alhazmi - avatar