php arrays + function

Asked

Viewed 45 times

-1

Good,

I have a doubt..

I’m using error system[] in array. I created a function that simply shows the design of the error + message

 warning_alert('Caracteres do tituto superiores a 4.');

 function warning_alert($text) {
  echo "
  <div class='alert warning'>
  <span class='closebtn'>&times;</span>  
  <strong><i class='fas fa-exclamation-circle'></i></strong> $text
  </div>"; 
 }

This is where it says the ERROR message. But it’s not working...

 $errors[] = warning_alert('Caracteres do tituto superiores a 4.');

This is the error message :

 if(strlen($ads_title) < 4 && strlen($ads_title) > 35) {

  $errors[] = warning_alert('Caracteres do tituto superiores a 4.'); 

 }

Array errors works this way.

          if(!empty($errors)) {  

              echo display_errors($errors);

          } else {

             if(move_uploaded_file($file_tmp, $file_destination)) {}

Any idea?

  • show error where??? what are you doing that does not show error?

  • not... This way does not give... $errors[] = warning_alert('Title characters greater than 4.'); It is as if no errors are heard...

  • Understand, I explained right up to... the $Errors[] array is where it shows all the errors of each check... but I want to show the error as I did, because WARNING_ALERT is a function with "ECHO $mensamgem"

  • I’ve edited, see now if you understand!

  • first, if you don’t need to store in an array! second inside a function you should return with Return and outside call echo warning_alert(""); then your code isn’t working because there are conceptual errors !!!

  • Can you correct me?... so I learn..

  • But.. I still need $errors [] = because it’s part of the system, and I can’t use ECHO

  • why? you need the $erros[]? that is not in your question the main reason! , is a confusing question!

  • I already edited, see the ERROR message!

  • with your code only this works (even having problems) if(strlen($ads_title) < 4 && strlen($ads_title) > 35) {&#xA; warning_alert('Caracteres do tituto superiores a 4.'); &#xA;}

  • Understand... I have to use $errors[] because it validates in another check. There is no way to Use Array $errors + function?????????????

  • Switch echo to Return in its function. I don’t know what the function that displays the data looks like, maybe you need to move it too.

Show 7 more comments

1 answer

0

Hello!!

Try to use the return instead of echo, because you want it to store in the array, but the function is no return.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.