Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP如何在条形图/图形中打印字符串中的字符数?_Php_Css_String_Function_Loops - Fatal编程技术网

PHP如何在条形图/图形中打印字符串中的字符数?

PHP如何在条形图/图形中打印字符串中的字符数?,php,css,string,function,loops,Php,Css,String,Function,Loops,我想用PHP在条形图/图形中显示字符串中的字符数。我有这个功能: function characterCount($amount) { $a = substr_count($amount, 'a'); $b = substr_count($amount, 'b'); return $a; return $b; } echo characterCount("abbaabbaaa"); 如何在条形图/图表中打印结果 Tnx 由于您似乎不了解return的工作原理,

我想用PHP在条形图/图形中显示字符串中的字符数。我有这个功能:

function characterCount($amount) {
    $a = substr_count($amount, 'a');
    $b = substr_count($amount, 'b');
    return $a;
    return $b;
}

echo characterCount("abbaabbaaa");
如何在条形图/图表中打印结果


Tnx

由于您似乎不了解
return
的工作原理,您的代码已经有了一个糟糕的开始

除此之外,已经有一个内置函数可以满足您的需要

至于在图表中显示,最简单的方法是在谷歌上快速搜索一些图形插件。就我个人而言,我会使用HTML,一组
s并排排列,其
高度设置为相对频率,但实际上列出的方式太多了。去试试看,如果你有更多的问题,再问一个更具体的问题:)


不过现在,我希望
count\u chars
函数能让您走上正确的道路。

您需要这样做

<style>
 .showbar {
    width: 8px;
    margin: 1px;
    display: inline-block;
    position: relative;
    background-color: #aeaeae;
    vertical-align: baseline;
}
</style>

<?php

function characterCount($amount)
{
    $a = substr_count($amount, 'a');
    $b = substr_count($amount, 'b');

   return array($a,$b);

}

$r=characterCount('aaab');
echo $r[0].'<div style="height: '.$r[0].'em;" class="showbar"></div>'.$r[1].'<div style="height: '.$r[1].'em;" class="showbar"></div>';

.展示栏{
宽度:8px;
保证金:1px;
显示:内联块;
位置:相对位置;
背景色:#aeaeae;
垂直对齐:基线;
}

你必须用谷歌搜索“PHP条形图”。我建议使用CSS创建一个带有颜色的Div。根据计算结果调整高度。数字越高,条形码越高。