I need urgent help, I couldn’t interpret this activity and I can’t fix the code

Asked

Viewed 56 times

-3

My teacher gave me a PHP lesson and I swear I understood practically nothing, ask him for help is out of the question mainly because he is very ignorant and does not like when other students ask any kind of question. Here’s the text he sent:

Atividade PHP

All I could do was code, which didn’t go very far:

<?php


$dados = array('<p>nome: <br>', 'idade: <br>', 'salário: 1500<br>', '<p>ativo', '<p>não ativo');

$bonificacao = ($dados[2] / 100 * 10) + 1500;


foreach ($dados as $funcionario1) 
{
    $funcionario1[0] . 'Ferdinando';
    $funcionario1[1] . '25';
    echo $funcionario1;
}

foreach ($dados as $funcionario2) 
{
    $funcionario2[0] . 'Irineu';
    $funcionario2[1] . '40';
    echo $funcionario2;
}

foreach ($dados as $funcionario3) 
{
    $funcionario3[0] . 'Letícia';
    $funcionario3[1] . '19';
    echo $funcionario3;
}


?> 

This was printed on the page:

inserir a descrição da imagem aqui

1 answer

1


It is an activity to show that you have learned to manipulate an array (array) and make loops, and use variables.

$dados = array(
  array(
    'nome' => 'joao',
    'salario' => 100,
    'ativo' => false
  ),
  array(
    'nome' => 'maria',
    'salario' => 200,
    'ativo' => true
  ),
);

$bonificacao = 0.10;

foreach ($dados as $funcionario) {
  if (! $funcionario['ativo']) {
    continue;
  }
  $funcionario['salario'] += floatval($funcionario['salario']) * $bonificacao;

  echo $funcionario['nome'] . ' - ' . $funcionario['salario'];
}
  • The funniest part is that he didn’t teach any of this, just showed the arrays, I’ve even complained about this teacher with the coordination, even so, thanks man!

  • Just to complement. " From PHP 5.4 you can also use the contracted array syntax, which you exchange array() for []" Follow DOC https://www.php.net/manual/en/language.types.array.php

Browser other questions tagged

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