Slicing PHP Array Into Table -


not sure if "slice" right word.. have following array stored in variable.

array ( [0] => design|1-cylinder 4-stroke engine, water-cooled [1] => displacement|373.2 cm³ [2] => bore|89 mm [3] => stroke|60 mm [4] => performance|32 kw (43 hp) [5] => starting aid|electric starter [6] => transmission|6 speed, claw shifted [7] => engine lubrication|wet sump ) 1  

note "|"'s separating content. content should in table this.

<table>     <thead>         <tr>             <td>title</td>             <td>details</td>         </tr>     </thead>     <tbody>         <tr>             <td>engine displacement</td>             <td>373.2 cm³</td>         </tr>         <tr>             <td>transmission</td>             <td>6 speed, claw shifted</td>         </tr>     </tbody> </table> 

how can write foreach statement this? not sure start? should separate arrays? not sure.

thanks in advance!

$adata = array(     'design|1-cylinder 4-stroke engine, water-cooled',     'displacement|373.2 cm³',     'bore|89 mm',     'stroke|60 mm',     'performance|32 kw (43 hp)',     'starting aid|electric starter',     'transmission|6 speed, claw shifted',     'engine lubrication|wet sump' ); ?> <table>     <thead>         <tr>             <th>title</th>             <th>details</th>         </tr>     </thead>     <tbody>     <?php         $icountdata = count( $adata );         for( $i = 0; $i < $icountdata; ++$i )         {             $atmp = explode( '|', $adata[ $i ] );             echo '<tr>';             echo '<td>';             echo $atmp[ 0 ];             echo '</td>';             echo '<td>';             echo $atmp[ 1 ];             echo '</td>';             echo '</tr>';         }     ?>     </tbody> </table> 

Comments

Popular posts from this blog

c++ - Delete matches in OpenCV (Keypoints and descriptors) -

java - Could not locate OpenAL library -

sorting - opencl Bitonic sort with 64 bits keys -