Scroll down a level in the array

Asked

Viewed 209 times

2

I have an array as follows:

Array
(
    [Fatura] => Array
        (
            [id] => 821
            [numero] => 5014
            [vencimento] => 22122014
            [emissao] => 22122013
            [cliente_id] => 123
            [Itens] => Array
                (
                    [Item1] => 0
                    [Item2] => 0
                    [Item3] => 0
                )
         )

And I’d like to leave it that way:

Array
(
    [Fatura] => Array
        (
            [id] => 821
            [numero] => 5014
            [vencimento] => 22122014
            [emissao] => 22122013
            [cliente_id] => 123
         )
     [Itens] => Array
         (
            [Item1] => 0
            [Item2] => 0
            [Item3] => 0
         )

Complete code:

<?php
echo $this->Form->create('Property');
echo $this->Html->tag('label', $this->Form->input('inactive', array('after' => 'Inativo', 'type' => 'checkbox', 'label' => false, 'div' => false)), array('class' => 'checkbox-inline'));
echo $this->Html->tag('label', $this->Form->input('featured', array('after' => 'Destaque', 'type' => 'checkbox', 'label' => false, 'div' => false)), array('class' => 'checkbox-inline'));
echo $this->Html->tag('label', $this->Form->input('slider', array('after' => 'Banner', 'type' => 'checkbox', 'label' => false, 'div' => false)), array('class' => 'checkbox-inline'));

echo "<div class='row'>";
echo $this->Html->div('col-xs-12 col-sm-5 col-md-4', $this->Form->input('property_status_id', array('type' => 'select', 'empty' => 'Selecione o Status...', 'options' => $property_statuses, 'label' => 'Status', 'div' => 'form-group', 'class' => 'form-control')));
echo "</div><div class='row'>";
echo $this->Html->div('col-xs-12 col-sm-5 col-md-4', $this->Form->input('property_type_id', array('type' => 'select', 'empty' => 'Selecione o Tipo...', 'options' => $property_types, 'label' => 'Tipo do Imóvel', 'div' => 'form-group', 'class' => 'form-control')));
echo $this->Html->div('col-xs-12 col-sm-5 col-md-4', $this->Form->input('property_subtype_id', array('type' => 'select', 'empty' => 'Selecione o Subtipo...', 'options' => $property_subtypes, 'label' => 'Subtipo do Imóvel', 'div' => 'form-group', 'class' => 'form-control')));
echo "</div><div class='row'>";
echo $this->Html->div('col-xs-12 col-sm-4 col-md-3', $this->Form->input('area', array('type' => 'text', 'label' => 'Área', 'div' => 'form-group', 'class' => 'form-control', 'placeholder' => 'm²', 'data-mask' => 'integer')));
echo "</div><div class='row'>";
echo $this->Html->div('col-xs-12 col-sm-4 col-md-2', $this->Form->input('bedrooms', array('type' => 'number', 'label' => 'Quartos', 'div' => 'form-group', 'class' => 'form-control')));
echo $this->Html->div('col-xs-12 col-sm-4 col-md-2', $this->Form->input('bathrooms', array('type' => 'number', 'label' => 'Suítes', 'div' => 'form-group', 'class' => 'form-control')));
echo "</div><div class='row'>";
echo $this->Html->div('col-xs-12 col-sm-4 col-md-2', $this->Form->input('parking_spaces', array('type' => 'number', 'label' => 'Vagas', 'div' => 'form-group', 'class' => 'form-control')));
echo $this->Html->div('col-xs-12 col-sm-4 col-md-3', $this->Form->input('parking_space_type', array('type' => 'select', 'label' => 'Tipo da Vaga', 'div' => 'form-group', 'class' => 'form-control', 'empty' => 'Selecione...', 'options' => array('Coberta' => 'Coberta', 'Descoberta' => 'Descoberta'))));
echo "</div><div class='row'>";
echo $this->Html->div('col-xs-12 col-sm-6 col-md-3', $this->Form->input('price', array('type' => 'text', 'label' => 'Preço do Imóvel', 'div' => 'form-group', 'class' => 'form-control', 'data-mask' => 'decimal')));
echo "</div><div class='row'>";
echo $this->Html->div('col-xs-12 col-sm-6 col-md-3', $this->Form->input('condominium_price', array('type' => 'text', 'label' => 'Preço do Condomínio', 'div' => 'form-group', 'class' => 'form-control', 'data-mask' => 'decimal')));
echo $this->Html->div('col-xs-12 col-sm-6 col-md-3', $this->Form->input('iptu', array('type' => 'text', 'label' => 'Preço do IPTU', 'div' => 'form-group', 'class' => 'form-control', 'data-mask' => 'decimal')));
echo $this->Html->div('col-xs-12 col-sm-6 col-md-3', $this->Form->input('iptu_frequency', array('type' => 'select', 'label' => 'Frequência do IPTU', 'div' => 'form-group', 'class' => 'form-control', 'empty' => 'Selecione...', 'options' => array('Mensal' => 'Mensal', 'Anual' => 'Anual'))));
echo "</div><div class='row'>";
echo $this->Html->div('col-xs-12 col-sm-4 col-md-3', $this->Form->input('property_view_id', array('type' => 'select', 'empty' => 'Selecione a Vista...', 'options' => $property_views, 'label' => 'Vista do Imóvel', 'div' => 'form-group', 'class' => 'form-control')));
echo $this->Html->div('col-xs-12 col-sm-4 col-md-3', $this->Form->input('property_position_id', array('type' => 'select', 'empty' => 'Selecione a Posição...', 'options' => $property_positions, 'label' => 'Posição do Imóvel', 'div' => 'form-group', 'class' => 'form-control')));
echo $this->Html->div('col-xs-12 col-sm-4 col-md-3', $this->Form->input('property_sun_type_id', array('type' => 'select', 'empty' => 'Selecione o Sol...', 'options' => $property_suntypes, 'label' => 'Tipo de Sol', 'div' => 'form-group', 'class' => 'form-control')));
echo "</div>";

foreach ($characteristics_imovel as $characteristic_i) {
    echo "<div class='col-xs-12 col-sm-6 col-md-4'>";
    echo $this->Html->tag('label', $this->Form->input('PropertyHasCharacteristic][' . $characteristic_i['Characteristic']['id'], array('after' => $characteristic_i['Characteristic']['name'], 'type' => 'checkbox', 'label' => false, 'div' => false)), array('class' => 'checkbox-inline'));
    echo "</div>";
}

echo $this->Html->div('col-xs-12 col-sm-4 col-md-3', $this->Form->input('postalcode', array('type' => 'text', 'label' => 'CEP', 'div' => 'form-group', 'class' => 'form-control', 'data-mask' => 'cep')));
echo $this->Html->div('col-xs-12 col-sm-4 col-md-4', $this->Form->input('city', array('type' => 'text', 'label' => 'Cidade', 'div' => 'form-group', 'class' => 'form-control')));
echo $this->Html->div('col-xs-12 col-sm-4 col-md-2', $this->Form->input('state', array('type' => 'text', 'label' => 'Estado', 'div' => 'form-group', 'class' => 'form-control')));
echo $this->Html->div('col-xs-12 col-sm-6 col-md-3', $this->Form->input('neighborhood', array('type' => 'text', 'label' => 'Bairro', 'div' => 'form-group', 'class' => 'form-control')));
echo $this->Html->div('col-xs-12 col-sm-6 col-md-5', $this->Form->input('address', array('type' => 'text', 'label' => 'Endereço', 'div' => 'form-group', 'class' => 'form-control', 'placeholder' => 'Logradouro')));
echo $this->Html->div('col-xs-12 col-sm-4 col-md-2', $this->Form->input('number', array('type' => 'text', 'label' => 'Número', 'div' => 'form-group', 'class' => 'form-control')));
echo $this->Html->div('col-xs-12 col-sm-8 col-md-5', $this->Form->input('complement', array('type' => 'text', 'label' => 'Complemento', 'div' => 'form-group', 'class' => 'form-control')));
echo $this->Html->div('col-md-12', $this->Form->end(array('label' => 'Salvar', 'class' => 'btn btn-success')));
  • i have one for each inside another, being that I would like the second for each to come on the first level, and not as the first level’s son...

  • I changed the code, the example was presented as Invoice, but actually it is a list of Properties with Features...

  • Sorry, first time here posting... I will try the solution below!

1 answer

1

If you’re just reformatting the array I think the simplest solution is this

$fatura = array(
    "Fatura" => (
            "id" => 821
            "numero" => 5014
            "vencimento" => 22122014
            "emissao" => 22122013
            "cliente_id" => 123
            "Itens" => (
                    "Item1" => 0
                    "Item2" => 0
                    "Item3" => 0
                )
         )
 );

 $itens = $fatura["Fatura"]["Itens"];

 unset($fatura["Fatura"]["Itens"]);
 $fatura["Itens"] = $itens;
  • Erlon, this is exactly what I needed... Thank you and sorry if I misexpressed myself! Abs!

  • For nothing expensive, welcome to the community, read http://answall.com/about. to have a better interactivity with everyone and understand how everything works.

Browser other questions tagged

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