<?php
$balls = [
["color" => "green", "cost" => 1, "weight" => 5],
["color" => "red", "cost" => 3, "weight" => 3],
["color" => "blue", "cost" => 5, "weight" => 2]
];
function grabBalls($balls, $ballsTaken) {
foreach($balls as $ball) {
$ballsTaken[] = $ball["color"];
if (count($ballsTaken) < 5) { grabBalls($balls, $ballsTaken);
} else {
}
return $ballsTaken;
}
}
$a = [];
grabBalls($balls, $a);
PD9waHAKZXJyb3JfcmVwb3J0aW5nKC0xKTsKCiRiYWxscyA9IFsKCQkJWyJjb2xvciIgPT4gImdyZWVuIiwgImNvc3QiID0+IDEsICJ3ZWlnaHQiID0+IDVdLAoJCQlbImNvbG9yIiA9PiAicmVkIiwgImNvc3QiID0+IDMsICJ3ZWlnaHQiID0+IDNdLAoJCQlbImNvbG9yIiA9PiAiYmx1ZSIsICJjb3N0IiA9PiA1LCAid2VpZ2h0IiA9PiAyXQoJCV07CgkKCgoKZnVuY3Rpb24gZ3JhYkJhbGxzKCRiYWxscywgJGJhbGxzVGFrZW4pIHsKCWZvcmVhY2goJGJhbGxzIGFzICRiYWxsKSB7CgkJJGJhbGxzVGFrZW5bXSA9ICRiYWxsWyJjb2xvciJdOwoJCQoJCWlmIChjb3VudCgkYmFsbHNUYWtlbikgPCA1KSB7CgkJCWdyYWJCYWxscygkYmFsbHMsICRiYWxsc1Rha2VuKTsKCQl9IGVsc2UgewoJCQl2YXJfZHVtcCgkYmFsbHNUYWtlbik7CgkJCgkJfQoJCQoJcmV0dXJuICRiYWxsc1Rha2VuOwkKCX0KfQoKJGEgPSBbXTsJCmdyYWJCYWxscygkYmFsbHMsICRhKTsKCnZhcl9kdW1wKCRhKTsK