Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to iterate fields of a shape in hacklang?

Tags:

hacklang

Say I have a shape like this

$something = shape(
  'some_key' => ...,
  'another_key' => ...,
  ...
);

How can I iterate each field of the shape? I'm looking for something like this

foreach ($something as $key) {
  ...
}
like image 964
kebab-case Avatar asked Nov 03 '25 00:11

kebab-case


1 Answers

Convert to a dict first with the built-in HH\Shapes::toDict then iterate:

foreach(HH\Shapes::toDict($something) as $k => $v) {
  // ...
}
like image 137
concat Avatar answered Nov 04 '25 19:11

concat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!