0

I have this array below. Inside it, i am storeing order status-es in a webshop.

    $rendeles_allapotok = array
(
    "0"=>"Új megrendelés",
    "1"=>"Függőben lévő",
    "2"=>"Feldolgozás alatt",
    "3"=>"Feldolgozva",
    "4"=>"Kiküldve",
    "5"=>"Postázva",
    "6"=>"Teljesítve",
    "7"=>"Sikertelen",
    "8"=>"Visszafizetve"
);

Now, this array has 2 element in each row, an id, and the status name.

But i want 3. I want to add a new parameter, the name will be product_back, and the value for that will be 0 or 1.

Thank you!

3
  • 1
    What do you mean by 2 elements in each row? what elements? and what rows? Commented Jan 19, 2018 at 20:13
  • 1
    Assuming the numerical keys are rows, I only see 1 element per row? Commented Jan 19, 2018 at 20:14
  • seems like you need a proper tutorial on how arrays work in PHP. Becaue you are getting it wrong. Commented Jan 19, 2018 at 20:23

3 Answers 3

2

This is an example, the array would have another array in it with both fields.

$rendeles_allapotok = array
(
    "0"=>array("name"=>"Új megrendelés","product_bak"=>"0"),
    "1"=>array("name"=>"Függőben lévő","product_bak"=>"1")
);
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you to, but someone writed before you, and i have to accept his answer. But yours is the same and usefull to.
2

I believe this is what you are looking for. You cannot store more than one value in an array without the use of a nested or multi dimensional array.

$rendeles_allapotok = array
(
    "0"=> array( 'product_back' => 0, 'status' => "Új megrendelés" ),
    "1"=> array( 'product_back' => 0, 'status' => "Függőben lévő" ),
    "2"=> array( 'product_back' => 0, 'status' => "Feldolgozás alatt" ),
    "3"=> array( 'product_back' => 0, 'status' => "Feldolgozva" ),
    "4"=> array( 'product_back' => 0, 'status' => "Kiküldve" ),
    "5"=> array( 'product_back' => 0, 'status' => "Postázva" ),
    "6"=> array( 'product_back' => 0, 'status' => "Teljesítve" ),
    "7"=> array( 'product_back' => 0, 'status' => "Sikertelen" ),
    "8"=> array( 'product_back' => 0, 'status' => "Visszafizetve )"
);

and to access it you would do this

echo $rendeles_allapotok[1]['status'];
echo $rendeles_allapotok[1]['product_back'];

Comments

1

I think what you are asking for is this i am not sure that you need a multi-dimensional array

Note: I substituted the array shorthand but it is not required

$rendeles_allapotok = [

    ['id'=>0, 'name'=>"Új megrendelés",   'product_back'=>0],
    ['id'=>1, 'name'=>"Függőben lévő",    'product_back'=>0],
    ['id'=>2, 'name'=>"Feldolgozás alatt",'product_back'=>0],
    ['id'=>3, 'name'=>"Feldolgozva",      'product_back'=>0],
    ['id'=>4, 'name'=>"Kiküldve",         'product_back'=>0],
    ['id'=>5, 'name'=>"Postázva",         'product_back'=>0],
    ['id'=>6, 'name'=>"Teljesítve",       'product_back'=>0],
    ['id'=>7, 'name'=>"Sikertelen",       'product_back'=>0],
    ['id'=>8, 'name'=>"Visszafizetve",    'product_back'=>0]
];

then to access the items in a loop you could do something like this

foreach($rendeles_allapotok as $row){
       echo "ID: {$row['id']}\n".
            "NAME: {$row['name']}\n";
       echo "Product Back:" . $row['product_back']==1?'  True':'  false';

}

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.