0
public function getCategories()
{
    $categories = array( 
        array('is-yemekleri',           'İş yemeklerine uygun.'),
        array('bekarliga-veda',         'Bekarlığa veda partileri için uygun.'),
        array('dogum-gunleri',          'Doğum günleri için uygun.'),
        array('mac-yayinlari',          'Maç yayınları mevcut.'),
        array('akdeniz-yunan-mutfagi',  'Akdeniz ve Yunan mutfağı mevcut.'),
        array('turk-osmanli-mutfagi',   'Türk ve Osmanlı mutfağı mevcut.'),
        array('italyan-mutfagi',        'İtalyan mutfağı mevcut.'),
        array('fransiz-mutfagi',        'Fransız mutfağı mevcut.'),
        array('uzakdogu-mutfagi',       'Uzakdoğu mutfağı mevcut.'),
        array('bar-pub',                'Bar-pub mevcut.'),
        array('brunch-kahvalti ',       'Brunch Kahvaltı mevcut.'),
        array('partiler',               'Partiler için uygun.'),
        array('cafe',                   'Cafe mevcut.'),
        array('club',                   'Club mevcut.'),
        array('dugun-mekanlari',        'Düğünler için uygun.'),
        array('fasil-mekanlari',        'Fasıl için uygun.'),
        array('et-restoranlari',        'Et restoranı bulunuyor.'),
        array('balik-restoranlari',     'Balık restoranı bulunuyor.'),
        array('meyhaneler',             'Meyhane bulunuyor.'),
        array('kina-geceleri',          'Kına geceleri için uygun.'),
    );

   return $categories;
}

I need to output this in my view file. There is a checkbox and it should look like this:

foreach($categories as $k => $v)
{
    İş yemeklerine uygun: (second value of array)
    <input type="checkbox" id="{ $k }" name="{ $k }" value="(first value of array)">
}

Output should be like this;

İş yemeklerine uygun:
<input type="checkbox" id="0" name="0" value="is-yemekleri">

Bekarlığa veda partileri için uygun.
<input type="checkbox" id="1" name="1" value="bekarliga-veda">

...

Kına geceleri için uygun.
<input type="checkbox" id="18" name="18" value="kina-geceleri">

How can I do this?

2 Answers 2

3

Each $v in your foreach-loop is an array.

First $v:

array('is-yemekleri','İş yemeklerine uygun.') //$v[0] and $v[1]

Second $v:

array('bekarliga-veda','Bekarlığa veda partileri için uygun.') //$v[0] and $v[1]

Third $v:

array('dogum-gunleri','Doğum günleri için uygun.') //$v[0] and $v[1]

etc...

I think you're looking for something like this:

foreach($categories as $k => $v)
{
      echo $v[1]; //second value of array
      echo '<input type="checkbox" id="' . $k .'" name="'.$k.'" value="' . $v[0] . '" />';
}
Sign up to request clarification or add additional context in comments.

Comments

0
array_map(function($item,$key){
    echo  'İş yemeklerine uygun:'.$item[1];
    echo '<input type="checkbox" id="'.$key.'" name="'.$key.'" value="'.$item[0].'">``<br/>';
},$categories,array_keys($categories));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.