I just can't figure out how to make the i-th variable in the loop.

for ( $i=1; $i<=3; $i++ ) { $Row = mysqli_fetch_assoc( mysqli_query($CONNECT, "SELECT * FROM `GGS_eq` WHERE `index` = '$_POST[search_index]' AND btn_no = '$i'") ); // если в таблице находим данный Индекс с нужной i-ой кнопкой, то: if ( $Row ) { $caller_title_btn_.$i = 'Кнопка: '.$Row['name']; } // если не находим, то: else { } } 

I need to assign $caller_title_btn_ (from 1 to 3). Neither can I figure out how to glue the temporary with $i .

    2 answers 2

    Try this way

     ${'caller_title_btn_' . $i} 

    But it is better to use

     $caller_title_btn[$i] 
    • Yes thank you!! This is what you need. - Vasily UK

    There is an answer to the question, but what you do is called a castel as there are other mechanisms, such as an array

     $caller_title_btn[$i] 

    think about the hemorrhoids that are waiting for you, you also have to place these variables somewhere else, use, expand, assign, etc.

    • Yes, of course, I wrote in the question that - most likely, I am doing something wrong ... and there are other ways. But in my particular case, this option is quite suitable. Thank! - Vasily UK
    • Option above or my @VasilyUK - Naumov
    • I used the ${'caller_title_btn_' . $i} ${'caller_title_btn_' . $i} , but then remade to $caller_title_btn[$i] . I do not know which of you was the first to offer the second option and who exactly helped. If the question is this ... - Vasily UK
    • @VasilyUK Well, I answered at 12 o'clock on October 4, and he finished off at 8 o'clock on October 4. I am the first - Naumov
    • Well, I don’t know what to say ... his first version also helped me, although yours are “prettier” and simpler, well, as I understood, more correctly. - Vasily UK