示例#1
0
文件: ATest.php 项目: ihor/Nspl
 /**
  * @expectedException \InvalidArgumentException
  */
 public function testMoveElementFromInvalidPosition()
 {
     moveElement([0, 1, 2], 3, 0);
 }
示例#2
0
文件: a.php 项目: rakesh-mohanta/Nspl
    echo sprintf("    %s. %s\n", $id, $user->name);
}
// 6. Create a map (name => age) from users data
$usersAgeByName = indexed($users, propertyGetter('name'), true, propertyGetter('age'));
echo "Users age:\n";
foreach ($usersAgeByName as $name => $age) {
    echo sprintf("    %s is %s y.o.\n", $name, $age);
}
// 7. Get users with unique age (unique values in multidimensional array)
$usersWithUniqueAge = array_values(indexed($users, propertyGetter('age')));
echo "Users with unique age:\n";
foreach ($usersWithUniqueAge as $user) {
    echo sprintf("    %s is %s y.o.\n", $user->name, $user->age);
}
// 8. Group users by age range
$usersByAgeRange = keySorted(indexed($users, function ($user) {
    return floor($user->age / 10) * 10;
}, false));
echo "Users by age range:\n";
foreach ($usersByAgeRange as $age => $usersGroup) {
    echo sprintf("    %s-%s: %s\n", $age, $age + 9, implode(', ', map(propertyGetter('name'), $usersGroup)));
}
// 9. Get all numbers less than 20 which are divisible by 3
$numbers = take(range(3, 20), 20, 3);
echo sprintf("Numbers less than 20 which are divisible by 3: %s\n", implode(', ', $numbers));
// 10. Re-order pets rating
$petsRating = moveElement(['dog', 'hamster', 'cat'], 2, 1);
echo "New pets rating:\n";
foreach ($petsRating as $pet) {
    echo sprintf("    %s\n", $pet);
}