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

**URL:** <https://forum.getkirby.com/t/check-for-variable-in-array-tricky-task-simple-answer/4330>\
**Category:** Questions\
**Tags:** v2\
**Created:** [June 5, 2016, 11:02pm UTC](https://forum.getkirby.com/t/check-for-variable-in-array-tricky-task-simple-answer/4330 "2016-06-05T23:02:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ToGe88](https://avatars.discourse-cdn.com/v4/letter/t/c68b51/32.png) [@ToGe88](https://forum.getkirby.com/u/ToGe88)\
**Post date:** [June 5, 2016, 11:02pm UTC](https://forum.getkirby.com/t/check-for-variable-in-array-tricky-task-simple-answer/4330/1 "2016-06-05T23:02:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![texnixe](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/texnixe/32/5754_2.png) [@texnixe](https://forum.getkirby.com/u/texnixe)\
**Post date:** [June 6, 2016, 6:16am UTC](https://forum.getkirby.com/t/check-for-variable-in-array-tricky-task-simple-answer/4330/2 "2016-06-06T06:16:06Z")

</div>

You want [`in_array()`](http://php.net/manual/de/function.in-array.php), to check if a value exists in an array.

---

<div class="post-metadata">

**Author:** ![ToGe88](https://avatars.discourse-cdn.com/v4/letter/t/c68b51/32.png) [@ToGe88](https://forum.getkirby.com/u/ToGe88)\
**Post date:** [June 6, 2016, 6:47am UTC](https://forum.getkirby.com/t/check-for-variable-in-array-tricky-task-simple-answer/4330/3 "2016-06-06T06:47:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![bnomei](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/bnomei/32/775_2.png) [@bnomei](https://forum.getkirby.com/u/bnomei)\
**Post date:** [June 6, 2016, 8:18am UTC](https://forum.getkirby.com/t/check-for-variable-in-array-tricky-task-simple-answer/4330/4 "2016-06-06T08:18:25Z")

</div>

or using toolkit array methods like get() or missing()  
[https://getkirby.com/docs/toolkit/api#a](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](https://getkirby.com/docs/toolkit/api/a/get)

like [ecco](https://getkirby.com/docs/cheatsheet/helpers/ecco) to echo.

---

<div class="post-metadata">

**Author:** ![ToGe88](https://avatars.discourse-cdn.com/v4/letter/t/c68b51/32.png) [@ToGe88](https://forum.getkirby.com/u/ToGe88)\
**Post date:** [June 8, 2016, 10:12am UTC](https://forum.getkirby.com/t/check-for-variable-in-array-tricky-task-simple-answer/4330/5 "2016-06-08T10:12:57Z")

</div>

in\_array worked a charm. Thanks for that @texnixe

---

<div class="post-metadata">

**Author:** ![distantnative](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.getkirby.com/distantnative/32/11319_2.png) [@distantnative](https://forum.getkirby.com/u/distantnative)\
**Post date:** [February 6, 2025, 4:57pm UTC](https://forum.getkirby.com/t/check-for-variable-in-array-tricky-task-simple-answer/4330/6 "2025-02-06T16:57:50Z")

</div>


