我有两个数字:
110009
114993
如何在PHP中回显此间隔之间的所有数字?
110009
110010
110011
110012
....
答案 0 :(得分:3)
您可以使用range()
函数。
$start = 110009;
$end = 114993;
foreach (range($start, $end) as $val) {
echo $val."\n<br />";
}
或者是常规的for
循环加1
$start = 110009;
$end = 114993;
for ($i = $start; $i <= $end; $i++) {
echo $i."\n<br />";
}
答案 1 :(得分:1)
使用import numpy as np
import matplotlib.pyplot as plt
A = np.array(((0,1),
(1,1),
(2,1),
(3,1)))
xfeature = A.T[0]
squaredfeature = A.T[0] ** 2
cubedfeature = A.T[0] ** 3
ones = np.ones(4)
b = np.array((1,2,0,3), ndmin=2 ).T
b = b.reshape(4)
order = 3
features = np.concatenate((np.vstack(ones), np.vstack(xfeature), np.vstack(squaredfeature), np.vstack(cubedfeature)), axis = 1)
xstar = np.matmul( np.matmul( np.linalg.inv( np.matmul(features.T, features) ), features.T), b)
plt.scatter(A.T[0],b, c = 'red')
u = np.linspace(0,3,1000)
plt.plot(u, u**3*xstar[3] + u**2*xstar[2] + u*xstar[1] + xstar[0], 'b-')
plt.show()
b = np.array((1,2,0,3), ndmin=2 ).T
y_prediction = u**3*xstar[3] + u**2*xstar[2] + u*xstar[1] + xstar[0]
SSE = np.sum(np.square(y_prediction - b))
MSE = np.mean(np.square(y_prediction - b))
print("Sum of squared errors:", SSE)
print("Mean squared error:", MSE)
循环:
for
答案 2 :(得分:0)
您可以使用range
完成您的目标。
$r = range( 110009, 114993, 1 );
然后打印值
foreach( $r as $i )echo $i;
答案 3 :(得分:0)
您可以使用range
和implode
:
echo implode("\n", range(110009, 114993));
答案 4 :(得分:0)
这是一个简单的函数,可以输出范围:
function output_number_range($start, $end) {
for ($n = ($start < $end ? $start : $end); $n <= ($end > $start ? $end : $start); $n++) {
echo $n . '<br>';
}
}
output_number_range(36, 3);
上面使用了一个简单的for循环,两个三元数允许您以任意顺序调用所需范围内最大或最小数字的函数。