Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Good day everyone! I have a database table. 
    [0] => stdClass Object
        (
            [id] => 8
            [username] => CLAVIK
            [k_1] => AAAAA
            [k_2] => SSSSSS
            [k_3] => DDDDD
            [k_4] => FFFFFF
            [k_5] => 
            [k_6] => 
            [k_7] => 
            [k_8] => 
            [k_9] => 
            [k_10] => 
            [kil_k] => 4
            [password] => $2y$10$Uwe1W8.IrA5.jM8IfgWTsOuTrfI1XQT5bdUq00aD7QNwAqsrDUgbm
            [regist] => 2022-11-18 12:22:19
        )
I need to create a new table con PHP in which there were columns without those fields that are zero
<pre>Array
(
    [0] => stdClass Object
        (
            [id] => 8
            
            [AAAAA] => 1222
            [ SSSSSS] => dddd
            [DDDDD] => 33rfr
            [FFFFFF] => now

What I have tried:

<pre>I am new to programming
Posted
Updated 18-Nov-22 23:45pm

1 solution

You could use a simple foreach loop to create the new array from all the non-zero values. See PHP: Arrays - Manual[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900