Check for variable in array? Tricky task, simple answer?

Hey there,
i’ll let you know what i’m trying to achieve:
i want to have an involvement-bar that shows parts in projects that the user has taken place in. Therefore i created a page with »involvement«-subpages. Those are able to get selected through a query inside the section(project)-blueprint. At this moment everything works fine.

In the frontend i create the bar with the different steps like this:

<div class="involvement--holder">
		<ul>
			<?php $parentSlug = $page->parent()->involvement()->split() ?>
			<?php $involvements = $site->index()->filterBy('template', 'involvement_web'); ?>
			<?php foreach($involvements as $involvement): ?>
				<li class="involvement--list-item <?php e((array_key_exists($involvement->slug(), $parentSlug)), 'active') ?>">
					<div class="involvement--progress-bar" style="">

					</div>
					<?php echo $involvement->slug() ?>
				</li>
			<?php endforeach ?>
		</ul>
	</div>

What i want now is to look if the slug of the step matches the value inside the comma separated output i get from the multiselect-field to set an active-class. I tried the ecco und the array_key_exists method, but none of them seem to work properly. Can anyone help with this? I guess there is a dead-simple solution for this…

Thanks so far
Tobi

You want in_array(), to check if a value exists in an array.

Ok thanks for that, i’ll give it a try this evening. But the rest seems good to you?

or using toolkit array methods like get() or missing()
https://getkirby.com/docs/toolkit/api#a

personally i use a::get() more often than in_array(), because i can choose a default value.
https://getkirby.com/docs/toolkit/api/a/get

like ecco to echo.

1 Like

in_array worked a charm. Thanks for that @texnixe