美文网首页
php html smarty 循环输出几个table

php html smarty 循环输出几个table

作者: A冲绳小光 | 来源:发表于2018-07-18 11:28 被阅读0次

前段时间在学习前端设计是循环输出几个table让我迷茫了很久,因为是个小白没有什么经验。

我想用输出json里内容

json 简单的   

 {

"M":["microSD","My Softbank","mineo"],

"Y":["Yahoo","Yahoo! JAPAN"],

"L":["LINE"],

"W":["Wi-Fi","Ymobile"]

}

类似   | KEY  |  VALVE |    的表格    *效果   |    M    |  microSD        |

          |          |  VALVE |                               |           |  My Softbank |  

          |          |  VALVE |                               |           |  mineo            |                                                                  


先把json转化为array 

$str = file_get_contents('./test.json');

$test_word_list = json_decode($str, true);  // 二维数组 

foreach ( $test_word_list as $key1 => $value) {

    foreach( $test_word_list [$key1] as $key => $value){

        $arr3[]=$value;  //获取一维数组的key

//key等于0的时候赋值$key1 、else的时候赋值为空 "";

if($key ==0){

    $arr4[]=$key1;

}else{

    $arr4[]="";

}

}

}

//key・value顺序颠倒

$arr1=array_combine($arr3,$arr4);

$sum=ceil((count($arr1)/5));  //5为想要循环的table   || $arr1  $sum输出到html 

html 可以用smarty写 

{assign var="i" value=0}

<table style="float:left">

{foreach $test_word_list as $key=>$value}

    {assign var="i" value=$i+1}

<tr>

    <td> {$value}  </td>

    <td> {$key}  </td>

</tr> 

{if $i == count( $test_word_list )}

</table>

{elseif (($i) % $sum == 0) }

</table><table style="float:left;">

{/if}

{/foreach}

以上就可以输出五个table 了 谢谢

相关文章

网友评论

      本文标题:php html smarty 循环输出几个table

      本文链接:https://www.haomeiwen.com/subject/gqfopftx.html