1-100之间如果$a=35 用什么方法可 以数组的形式取出35包含的所有的10 和余数floor($a%10) 赋值给$b呢

WBOY
Release: 2016-06-23 13:10:57
Original
993 people have browsed it

1-100之间如果$a=35 用什么方法可 以数组的形式取出35包含的所有的10 和余数floor($a%10) 赋值给$b呢 ,结果应该是 10 10 10 5, 我是小白 希望大家赐教,万分感谢!


回复讨论(解决方案)

这个意思?
http://ideone.com/fE3OsH

<?php$a = 35;$b = array();while ($a>10){	array_push($b, 10);	$a -= 10;}if ($a) {	array_push($b, $a);}print_r($b);
Copy after login

$a = 35;$b = array_merge(array_fill(0, intval($a/10), 10), array($a % 10));print_r($b);
Copy after login
Array(    [0] => 10    [1] => 10    [2] => 10    [3] => 5)
Copy after login

非常感谢!!麻烦再继续问个问题
$a = 35;
$b = array_merge(array_fill(0, intval($a/10), 10), array($a % 10));
print_r($b);

如果$a也是个数组,例如 $a =Array (35 , 26) ,要怎么把这个多维数组用$c表示出来呢

$a = array (35 , 26);$c = array_map(function($a) {  return array_merge(array_fill(0, intval($a/10), 10), array($a % 10));  }, $a);print_r($c);
Copy after login
Array(    [0] => Array        (            [0] => 10            [1] => 10            [2] => 10            [3] => 5        )    [1] => Array        (            [0] => 10            [1] => 10            [2] => 6        ))
Copy after login

谢谢,谢谢,感激涕零!!!!完美解决

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template