Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.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 - Fatal编程技术网

Php 生成权重&;高度数组

Php 生成权重&;高度数组,php,Php,我如何创建一个php函数来计算,然后生成一个数组,该数组表示任何给定范围(比如4英尺到7英尺)的英制度量值及其等效度量值(对于人类) 例如: Array ( [1] => 4'8"(142cm) [2] => 4'9"(144.5cm) [3] => 4'10"(147cm) ) ……等等。重量(磅/千克)也有相同的例子。如果有人能让我在这方面领先一步,我将不胜感激。这可能会为您指明正确的方向。。还没有测试,但应该足以让你开始。非常简单的概念。我让你从

我如何创建一个php函数来计算,然后生成一个数组,该数组表示任何给定范围(比如4英尺到7英尺)的英制度量值及其等效度量值(对于人类)

例如:

Array
(
    [1] => 4'8"(142cm)
    [2] => 4'9"(144.5cm)
    [3] => 4'10"(147cm)
)

……等等。重量(磅/千克)也有相同的例子。如果有人能让我在这方面领先一步,我将不胜感激。

这可能会为您指明正确的方向。。还没有测试,但应该足以让你开始。非常简单的概念。我让你从英尺+英寸的绳子开始-现在你应该能够想出如何把米放在那里

// $startHeight and $endHeight are in inches

function createRange($startHeight,$endHeight){

// calculate the difference in inches between the heights
$difference = $endHeight - $startHeight;

// create an array to put the results in
$resultsArray; 

//create a loop with iterations = $difference

for($i=0;$i<$difference;$i++)
{
    // create the current height based on the iteration
    $currentHeight = $startHeight + $i;

    // convert the $currentHeight to feet+inches
    // first find the remainder, which will be the inches
    $remainder = ($currentHeight % 12);
    $numberOfFeet = ($currentHeight - $remainder)/12;

    // build the feet string
    $feetString = $numberOfFeet.'&apos;'.$remainder.'&quot;';

    // now build the meter string using a similar method as above
    // and append it to $feetString, using a conversion factor

    // add the string to the array
    $resultsArray[] = $feetString;

}

// return the array
return $resultsArray;

}
/$startHeight和$endHeight以英寸为单位
函数createRange($startHeight,$endHeight){
//计算两个高度之间的差值(以英寸为单位)
$difference=$endHeight-$startHeight;
//创建一个数组以放入结果
$resultsArray;
//创建迭代次数为$difference的循环

对于($i=0;$i这可能会为您指明正确的方向。您还没有测试过,但它应该足以让您开始。非常简单的概念。我让您从英尺+英寸的字符串开始-现在您应该能够了解如何将仪表放入其中

// $startHeight and $endHeight are in inches

function createRange($startHeight,$endHeight){

// calculate the difference in inches between the heights
$difference = $endHeight - $startHeight;

// create an array to put the results in
$resultsArray; 

//create a loop with iterations = $difference

for($i=0;$i<$difference;$i++)
{
    // create the current height based on the iteration
    $currentHeight = $startHeight + $i;

    // convert the $currentHeight to feet+inches
    // first find the remainder, which will be the inches
    $remainder = ($currentHeight % 12);
    $numberOfFeet = ($currentHeight - $remainder)/12;

    // build the feet string
    $feetString = $numberOfFeet.'&apos;'.$remainder.'&quot;';

    // now build the meter string using a similar method as above
    // and append it to $feetString, using a conversion factor

    // add the string to the array
    $resultsArray[] = $feetString;

}

// return the array
return $resultsArray;

}
/$startHeight和$endHeight以英寸为单位
函数createRange($startHeight,$endHeight){
//计算两个高度之间的差值(以英寸为单位)
$difference=$endHeight-$startHeight;
//创建一个数组以放入结果
$resultsArray;
//创建迭代次数为$difference的循环

对于($i=0;$i,您对社区的实际期望是什么?转换非常简单(简单的数学),数组生成也很简单(
foreach
for
)@虫族毫无帮助,尽管你的评论似乎有些粗鲁,但你可能是对的,因为这对你来说是一件小事。然而,对我来说情况不一样。我不知道实现这一点的最佳方法是什么。这是一个问题,在一个回答他们的社区。如果这件事如此微不足道,请教我一些东西,并为自己赢得一些p你今天帮助了一个人,而不是批评我对这个社区的看法和判断我的能力。可能重复@Lea:好吧,把你的问题分成几个小问题。第一个问题:生成一行数字。另一个问题:假设数字是以英尺为单位的长度-将其转换为met呃。你陷入了其中哪一个?编程中的每个问题都是由小问题组成的。每个程序员只是迭代地一个接一个地解决小问题。PS:我问你对我们有什么期望,因为你现在的问题看起来像:“这是一项任务,请为我做那件事。”@虫族我要求在我的问题的底部有一个领先的位置,而不是“填鸭式的”。这个问题很明确,问的是“如何做”,而不是“有人能做到这一点…”。我正在寻找如何实现这一目标的想法,因为我以前没有这样做过,我很困惑从哪里开始,找不到关于它的讨论。可能在我的头脑中使事情变得更加复杂,只需要朝着正确的方向推动一点。我会接受你的建议,尝试分解所有事情,然后从那里开始。实际做什么你期望从社区得到什么?转换是一个非常简单的过程(简单的数学),数组的生成也很简单(
foreach
for
)@虫族毫无帮助,尽管你的评论似乎有些粗鲁,但你可能是对的,因为这对你来说是一件小事。然而,对我来说情况不一样。我不知道实现这一点的最佳方法是什么。这是一个问题,在一个回答他们的社区。如果这件事如此微不足道,请教我一些东西,并为自己赢得一些p你今天帮助了一个人,而不是批评我对这个社区的看法和判断我的能力。可能重复@Lea:好吧,把你的问题分成几个小问题。第一个问题:生成一行数字。另一个问题:假设数字是以英尺为单位的长度-将其转换为met呃。你陷入了其中哪一个?编程中的每个问题都是由小问题组成的。每个程序员只是迭代地一个接一个地解决小问题。PS:我问你对我们有什么期望,因为你现在的问题看起来像:“这是一项任务,请为我做那件事。”@虫族我要求在我的问题的底部有一个领先的位置,而不是“填鸭式的”。这个问题很明确,问的是“如何做”,而不是“有人能做到这一点…”。我正在寻找如何实现这一目标的想法,以前没有这样做过,我很难从何处开始,也找不到关于它的讨论。可能在我的头脑中使事情变得更加复杂,只需要朝着正确的方向推动一下。我会接受你的建议,尝试将所有事情分解,然后从那里开始。