Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/variables/2.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
如何从3位数的php变量中打印独立的数字?_Php_Variables - Fatal编程技术网

如何从3位数的php变量中打印独立的数字?

如何从3位数的php变量中打印独立的数字?,php,variables,Php,Variables,就像我试图使用SQL查询来使用数据一样。 之后,PHP变量包含123。 现在我想在html页面上分别打印1、2和3。字符串基本上是一个字符数组,因此您可以轻松地按位置访问每个字符。您需要确保您的值是一个字符串-如果它是您需要的数字 在html页面上单独显示是什么意思? <?php $value = 123; // Cast our value to a string $stringValue = (string) $value; $firstChar = $stringValue[0]

就像我试图使用SQL查询来使用数据一样。 之后,PHP变量包含123
现在我想在html页面上分别打印1、2和3

字符串基本上是一个字符数组,因此您可以轻松地按位置访问每个字符。您需要确保您的值是一个字符串-如果它是您需要的数字

在html页面上单独显示是什么意思?
<?php
$value = 123;

// Cast our value to a string
$stringValue = (string) $value;

$firstChar = $stringValue[0];
$secondChar = $stringValue[1];
$thirdChar = $stringValue[2];
echo $firstChar.PHP_EOL;
echo $secondChar.PHP_EOL;
echo $thirdChar.PHP_EOL;