# Using a variable in an array index

**URL:** <https://forum.kirupa.com/t/using-a-variable-in-an-array-index/274601>\
**Category:** Uncategorized\
**Created:** [October 31, 2008, 11:08pm UTC](https://forum.kirupa.com/t/using-a-variable-in-an-array-index/274601 "2008-10-31T23:08:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mlk](https://avatars.discourse-cdn.com/v4/letter/m/e56c9b/32.png) [@mlk](https://forum.kirupa.com/u/mlk)\
**Post date:** [October 31, 2008, 11:08pm UTC](https://forum.kirupa.com/t/using-a-variable-in-an-array-index/274601/1 "2008-10-31T23:08:08Z")

</div>

hello kirupians

I’ve build an array such as

$list = [‘apple’ =\> ‘red’, ‘banana’ =\> ‘yellow’]

But I can’t seem to be able to call that in php, here’s what I’m doing now

> 

$index = ‘apple’;  
echo "Colour of $index is ".$list[$index];

Did I do something wrong ?
